문제

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>

도움이 되었습니까?

해결책

You could use :first-child:

$('.bar:first-child').wrap('<div class="test"/>');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top