0

I need to target every first div.bar. I went through many ways but with no success with jQuery, although it seemed easy at first.

I need this in order to wrap all the div.bar after, but this I can do with .wrapAll() afterwards.

<div id="aaa">
  <div class="bar" />
  <div class="bar" />
  <div class="bar" />
</div>
<span id="bbb">
          <div class="bar" />
          <div class="bar" />
          <div class="bar" />
        </span>
<div id="ccc">
  <div class="bar" />
  <div class="bar" />
</div>
double-beep
  • 5,031
  • 17
  • 33
  • 41
Nirs
  • 45
  • 8

1 Answers1

1

You could use :first-child:

$('.bar:first-child').wrap('<div class="test"/>');
A. Wolff
  • 74,033
  • 9
  • 94
  • 155