Jquery index () with a specific selector ...?

I have a parent with li, and pointing to li, I want to get it as a child.

For this, I used:

li.index()

Now ... I have one more condition, it should find the index only among these child elements that have a mapping: the block property in css.

I tried some other methods, but I could not solve it. Any ideas?

Edit : PS: or rather, for those that don't have a display: none property.

EDIT 2 : Well, all of this requires a reference to the parent or specific identifiers, but what if they only have a pointer to li, for example:

<ul>
<li>Foo</li>
<li>Bar</li>
<li>Fiz</li>
<li>Buz</li>
</ul>

li=$('li:nth-child(n)');

Now suppose I know only one variable, and I want this index among them that do not have a css display: none propery ...

:

li.add(li.siblings()).filter(':visible').index( li );

, .:)

+5
3

:

<ul>
  <li>Foo</li>
  <li>Bar</li>
  <li style="display:none">Fiz</li>
  <li>Buz</li>
</ul>

( ) li :

// 2
$("li:last").index("li:visible");

:visible :

// 3
$("li:last").index("li");

:

:

var lastItem = $("#parent li:last");

:

var index = $(lastItem).index("#parent li:visible");

2:

var index = lastItem.parent().find("li").index( lastItem );
+5

ANS

   var listItem = document.getElementById('bar');
   alert('Index: ' + $('li').index(listItem)); 

http://jsfiddle.net/VqeHW/

0

: , .class:

$('#theList .visible').each(function () {
  var index = $('#theList .visible').index(this);
});
0

All Articles