bholagabbar bholagabbar - 5 months ago 14
jQuery Question

jQuery replacing only one instance of .first()

Say I have something like this:

<div class="carousel-inner onebyone-carosel" id="carousel-inner">
<div class="item">
<!--Stuff-->
</div>
</div>

<!--Same thing again-->

<div class="carousel-inner onebyone-carosel" id="carousel-inner">
<div class="item">
<!--Stuff-->
</div>
</div>


Now, when I use
$(".carousel-inner div:first").addClass('active');
, the class
active
is added only the
div
of the first
carousel-inner
. The second one remains as it is.

Is this the expected behavior? Or am I missing something?

Don Don
Answer

Yes, it would add it to first div only.

Do this:

$(".carousel-inner div:first-child").addClass('active');
Comments