JQuery: select all elements where attribute is greater than value

I know that to filter an element with atttribute named attrName, which has the value attrValue, I do:

filter("[attrName='attrValue']") 

but looking at the documents http://api.jquery.com/category/selectors/ I don’t see a choice to select all the elements st attrName> attribute value

Will it work

  filter("[attrName>'attrValue']") 
+52
jquery css-selectors
Apr 10 '10 at 14:11
source share
3 answers

You can do this using the overload function .filter() , for example:

 .filter(function() { return $(this).attr("attrName") > "someValue"; }) 
+82
Apr 10
source share

JQuery.filter () solution:

 $("selector").filter(function() { return $(this).attr("my-attr") > 123; }); 
+21
Apr 10 '10 at 14:18
source share

Be careful if you play with integers, make sure you use parseInt() .

 $("selector").filter(function() { return parseInt($(this).attr("my-attr")) > 123; }); 
+6
Apr 10 '17 at 19:40
source share



All Articles