Created
June 19, 2013 12:15
-
-
Save dfang/5813836 to your computer and use it in GitHub Desktop.
custom filter for jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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