Last active
March 14, 2018 23:26
-
-
Save andyvanee/2876024 to your computer and use it in GitHub Desktop.
jQuery custom pseudo selectors
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
| // 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