Hailwood
Hailwood

Reputation: 92691

jquery selectors

I am making a jquery plugin.

You are given an object which contains several divs.

is there anyway to select the say, 3rd child div?

Upvotes: 0

Views: 67

Answers (4)

Pranay Rana
Pranay Rana

Reputation: 176956

.get() A zero-based integer indicating which element to retrieve.

($('div').get(3));

Upvotes: 1

redsquare
redsquare

Reputation: 78687

See .eq - remember it is 0 based

e.g for the third div in an object containing a list of elements

$someObject.find('div:eq(2)')

Upvotes: 5

Michel
Michel

Reputation: 9440

you can give them a className and use each or simple select the div, and count your selections

var n = 0    
$("div div").each(function() {
      n++;
      if(n == 3){
            $(this).html("do your thing");
      }
});

Upvotes: -1

powtac
powtac

Reputation: 41080

Select the third div:

$('div').eq(2)

Upvotes: 0

Related Questions