I'd like to fetch the index of an element in relation to all visible siblings.
A td.index()
does fetch the index of the td to all other td siblings.
But what when some of those TDs are set to display:none
. I want to exclude them when calculating the index. td.index(':visible')
does not seem to work.
var $td = $("#theTD")
$td.siblings(":visible").andSelf().index($td);
The above should do what you're asking. Basically get the set of elements you want to search within and then get the index of your element within them.
http://jsfiddle.net/3NYY9/
EDIT: As of jquery 1.8 andSelf
has been deprecated and addBack
should be used in its place:
var $td = $("#theTD")
$td.siblings(":visible").addBack().index($td);
http://jsfiddle.net/3NYY9/45/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With