Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nextUntil() jQuery selector

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);
like image 305
theHack Avatar asked Nov 20 '25 22:11

theHack


2 Answers

.nextUntil() takes a selector not an object. Try:

alert( a.eq(0).nextUntil( '.' + a.eq(3).attr('class') ).length );

http://jsfiddle.net/L82JU/3/

like image 133
mVChr Avatar answered Nov 23 '25 10:11

mVChr


$.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/

like image 22
Gary Chambers Avatar answered Nov 23 '25 12:11

Gary Chambers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!