Skip to content

Instantly share code, notes, and snippets.

@andyvanee
Last active March 14, 2018 23:26
Show Gist options
  • Select an option

  • Save andyvanee/2876024 to your computer and use it in GitHub Desktop.

Select an option

Save andyvanee/2876024 to your computer and use it in GitHub Desktop.
jQuery custom pseudo selectors
// Returns true if the parent element contains div.nav_level2
jQuery.expr[":"].subnav = function(obj){
return jQuery(obj).parent().find("div.nav_level2").length;
};
// Using it
$("nav li>a:subnav").click(function(ev){});
$("nav li>a").not(":subnav").css("background-image", "none");
// Simulate :blank CSS selector
$.expr[":"].blank = function(obj){
return /^[\s|\u00A0]*$/.exec($(obj).text()) !== null;
};
$('p:blank').remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment