Skip to content

Instantly share code, notes, and snippets.

@dfang
Created June 19, 2013 12:15
Show Gist options
  • Save dfang/5813836 to your computer and use it in GitHub Desktop.
Save dfang/5813836 to your computer and use it in GitHub Desktop.
custom filter for jquery
$.expr[':'].external = function(elem,index,match) {
var url = elem.href || elem.src,
loc = window.location;
return !!url.match(new RegExp('^' + loc.protocol + '//' + '(?!' + loc.hostname + ')' ));
};
// You can now use it within your selectors:
// Find all external anchors:
$('a:external');
// Find all external script elements:
$('script:external');
// Determine if link is external:
$('a#mylink').is(':external'); // true or false
[external link]: http://james.padolsey.com/javascript/extending-jquerys-selector-capabilities/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment