Domanda

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>

È stato utile?

Soluzione

You could use :first-child:

$('.bar:first-child').wrap('<div class="test"/>');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top