jQuery .next() doesn't work?

2019-02-24 11:08发布

问题:

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?

回答1:

I should use nextAll() not next

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

demo working