Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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']") 
like image 233
Ankur Avatar asked Apr 10 '10 14:04

Ankur


People also ask

Which selector is faster in jQuery?

ID and Element selector are the fastest selectors in jQuery.

How do I select all elements with ID?

The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

Can you use CSS selectors in jQuery for selecting elements?

jQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element. name − The name of the property to access.


1 Answers

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

.filter(function() {   return $(this).attr("attrName") > "someValue"; }) 
like image 111
Nick Craver Avatar answered Sep 30 '22 05:09

Nick Craver