jQuery: Selecting all elements where attribute is greater than a value

Ankur picture Ankur · Apr 10, 2010 · Viewed 40.2k times · Source

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

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

but looking at the docs http://api.jquery.com/category/selectors/ I can't see an option to select all elements s.t. attrName>attrValue

Will this work

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

Answer

Nick Craver picture Nick Craver · Apr 10, 2010

You can do this using the function overload of .filter(), like this:

.filter(function() {
  return $(this).attr("attrName") > "someValue";
})