开发者

How to get collection of subelements at specific index in jquery

开发者 https://www.devze.com 2023-03-25 19:03 出处:网络
I have sample DOM: <div class=\"x\"> <div class=\"y\"> <span>a</span> <span>b</span>

I have sample DOM:

<div class="x">
  <div class="y">
    <span>a</span>
    <span>b</span>
    <span>c</span>
  </div>
  <div class="y">
    <span>d</span>
    <span>e</span>
    <span>f</span>
  </div>  
</div>

The jquery expression $(".x .y span") returns all 6 span elements (a,b,c,d,e,f). The expression $(".x .y span:eq(1)") returns only开发者_开发问答 one span element - b.

How should look expression returning collection of subelements at specific index, for exmaple at index 1 (b,e).

Regards


It should be

$(".x .y span:nth-child(2)")


e is not in the .y selector ! fix that before

0

精彩评论

暂无评论...
验证码 换一张
取 消