I'm searching to filter elements with a range. Exemple, with a element list:
<ul>
<li data-price="25">Foo</li>
<li data-price="50">Bar</li>
<li data-price="125">Baz</li>
<li data-price="150">Biz</li>
</ul>
I want to extract all li with data-price >= 50 and <= 125. Does exist a selector who can do it simply ? If not What can be a simple way to do it ?
You can use .filter() function:
$('ul li').filter(function(){
return($(this).data('price')>=50 && $(this).data('price')<=125)
});
Working Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With