jwaliszko
jwaliszko

Reputation: 17074

How to get collection of subelements at specific index in jquery

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

Upvotes: 0

Views: 80

Answers (2)

user831624
user831624

Reputation:

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

Upvotes: 0

Tomalak
Tomalak

Reputation: 338326

It should be

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

Upvotes: 1

Related Questions