why does it return an error?
http://jsfiddle.net/L82JU/
Uncaught TypeError: Object [object Object] has no method 'replace'
I want to select the first child of .x until the 3rd child of .x
html
<div class="x">
<div class="a">a</div>
<div class="b">b</div>
<div class="c">c</div>
<div class="d">d</div>
<div class="e">e</div>
</div>
jquery
a=$('.x').children();
alert(a.eq(0).nextUntil(a.eq(3)).length);
.nextUntil() takes a selector not an object. Try:
alert( a.eq(0).nextUntil( '.' + a.eq(3).attr('class') ).length );
http://jsfiddle.net/L82JU/3/
$.nextUntil expects a string, not an object. In your example, you're passing an object, which has no replace method. You need to pass the selector.
You could try this instead:
alert(a.eq(0).nextUntil('.d').length);
Or if you don't know the specific selector ahead of time:
alert(a.eq(0).nextAll().slice(2).length);
http://jsfiddle.net/L82JU/5/
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