I have html and want to select interval 5 elements from 10'th position. How to do this?
My html:
<div class="chaire">
<img alt="" src="2.gif">
</div>
<div class="chaire">
<img alt="" src="2.gif">
</div>
<div class="chaire">
<img alt="" src="2.gif">
</div>
<div class="chaire">
<img alt="" src="2.gif">
</div>
...
<div class="chaire">
<img alt="" src="2.gif">
</div>
I try with jquery:
$(".chaire:gt(10):lt(15)");
but it select me div and img tags. But I need div tags.
Your code does the job just fine, and selects only <div>
elements. Take a look at this example fiddle, which finds 5 <div>
elements after the 10th (:gt(9):lt(15)
).
<div>
elements. No <img>
elements will be selected. As rcravens had already pointed out, the two selectors modify the result separately, so you need to use :lt()
first - :lt(15):gt(9)
.
Updated example at: http://jsfiddle.net/teQkf/3/. The next part of the example code finds the <img>
elements within the result and changes their src to something else.
You're better off using slice
, which is only a single operation on the result and therefore less confusing, not to mention faster:
$(".chaire").slice(10,15);
(example)
try this:
$(".chaire:gt(10):lt(5)");
Here is a jFiddle to play around with.
http://jsfiddle.net/rcravens/m3j6K/
It looks like chaining the 'gt' and 'lt' selectors means 'lt' is applied to what remains after the 'gt'.
Bob
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