how to remove elements greater or equal to a particular number using jquery?
<div id="1" class="testList"><p>anything</p></div>
<div id="2" class="testList"><p>anything</p></div>
<div id="3" class="testList"><p>anything</p></div>
<div id="4" class="testList"><p>anything</p></div>
<div id="5" class="testList"><p>anything</p></div>
<div id="6" class="testList"><p>anything</p></div>
<div id="7" class="testList"><p>anything</p></div>
<div id="8" class="testList"><p>anything</p></div>
<div id="9" class="testList"><p>anything</p></div>
Example, I need to remove all div element's greater than and equal to id 5... My attempt is using a variable called clear
$(".testList:gt('"+clear+"') p").remove();
How do I use greater than or equal to in jquery?
If you want to test against the ID, you need a .filtering function:
var clear = 5;
$('.testList').filter(function(i) {
return (this.id >= clear);
}).remove();
http://jsfiddle.net/mblase75/jtYgJ/
WARNING: In HTML 4, IDs that start with a number are illegal, although most browsers will allow them anyway. HTML5 allows numerical IDs.
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