Skip to content

Instantly share code, notes, and snippets.

@bgrins
Created November 26, 2012 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrins/4148366 to your computer and use it in GitHub Desktop.
Save bgrins/4148366 to your computer and use it in GitHub Desktop.
Create a sizzle expression in jQuery 1.8 and older
// Create a sizzle expression using jQuery 1.8 style and older style.
// This one returns elements which have an ID that ends with a string passed in.
// <div id="prefix_test"></div>
// $(":asp(test)")
if ($.expr.createPseudo) {
jQuery.expr[':'].asp = $.expr.createPseudo(function( id ) {
return function(elem) {
return elem.id && elem.id.match(id + "$")
};
});
}
else {
jQuery.expr[':'].asp = function(elem, i, match) {
return !!(elem.id && elem.id.match(match[3] + "$"));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment