Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .next() doesn't work?

I am trying to use jQuery .next() with a selector, seems that I missed something.

My code:

<div>1</div>
<span>2</span>
<div class="dd">3</div>
<div>4</div>
$('div').next(".dd").css('color','red');

If I change the span to div it works, but this way doesn't!

Any help?

like image 477
ilyes kooli Avatar asked Jun 02 '26 07:06

ilyes kooli


1 Answers

I should use nextAll() not next

$('div').nextAll(".dd").css('color','red');

demo working

like image 52
ilyes kooli Avatar answered Jun 05 '26 02:06

ilyes kooli