Custom jQuery selector

/ Published in: jQuery
Save to your folder(s)

Example given in the book jQuery Enlightenment.

Create your own custom selectors in jQuery and manipulate as usual.

Copy this code and paste it in your HTML
  1. $.expr[":"].positionAbsolute = function(el){
  2. return $(el).css("position") === "absolute";
  3. };
  5. //Usage
  6. alert($(":positionAbsolute").length); //alerts number elements positioned absolutley
  8. //Or use a filter
  9. $("div").filter(function(){return $(this).css('position') === 'absolute';});

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.