[jQuery] Re: Finding position among siblings

2008-07-15 Thread Jonathan Sharp
$('div').click(function() {
// Will give you the index out of just the DIV tags
var index = $(this).parent().find('> ' + this.tagName).index(this);

// Will give you the index out of all siblings
var index = $(this).parent().find('> *').index(this);
});

Cheers,
-Jonathan


On Tue, Jul 15, 2008 at 10:57 AM, ml1 <[EMAIL PROTECTED]> wrote:

>
> Is there an efficient, cross browser jquery way to find a node's
> position among it's siblings?
>
> Ie if I have ten  nodes next to each other and the user clicks on
> the third one, what's the best way to tell that it's the third one?
>
> Thanks!
>


[jQuery] Re: Finding position among siblings

2008-07-15 Thread Josh Nathanson


Check into the index() method.

-- Josh

- Original Message - 
From: "ml1" <[EMAIL PROTECTED]>

To: "jQuery (English)" 
Sent: Tuesday, July 15, 2008 8:57 AM
Subject: [jQuery] Finding position among siblings




Is there an efficient, cross browser jquery way to find a node's
position among it's siblings?

Ie if I have ten  nodes next to each other and the user clicks on
the third one, what's the best way to tell that it's the third one?

Thanks!