hyperlink - jQuery: select all internal links EXCLUDING links to downloadable files -


i'm using following piece of jquery code select internal links ...

var siteurl = "http://" + top.location.host.tostring(); var $internallinks = $("a[href^='"+siteurl+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']"); 

and works fine. problem i'm facing don't want select internal links directly points downloadable files (e.g. http://www.example.com/downloadable.pdf)

extension (pdf, mp3, jpg, gif, webm ... etc)

now question is, how exclude such internal links above criteria?

or if use .not() function exclude such links, question be, how select internal links directly points such downloadable files?

a simple solution use filter or not regular expression reject links don't want:

var $internallinks = $("a[href^='"+siteurl+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']");  $internallinks = $internallinks.not(function () {   return $(this).attr('href').match(/\.(pdf|mp3|jpg|jpeg|etc)$/i); }); 

the opposite, assuming of "not downloadable" urls end in .html or .htm, filter links extensions:

$internallinks = $internallinks.filter(function () {   return $(this).attr('href').match(/\.html?/); }); 

Comments

Popular posts from this blog

android - Automated my builds -

c# - Create a custom control in Corel Draw X6 using only VSTA -

ruby on rails - Difference between "Redmine on Heroku" and "Installing Redmine" documentation -