jQuery live sibling-selector not working
I have this CSS selector, which just won't bind .live()
, but works perfectly with .bind()
:
$('.treeView li ~ :has("ul")').prev('li')
I've read somewhere, that using the .prev()
and .next()
could be troublesome coupled with .live()
, so I wanted to create an pure CSS selector (or ANYTHING that works with .live()
!) to do the job - but I just can't figure it out!
Here's what I want to do:
Select all li
-elements, which is followed by an li
containing an ul
.
Here's an HTML markup example, I want to select the ones where the comment says "selected"
<div class="treeView" id="processSegmentsTree">
<ul>
<li>Ostetanke</li> //selected
<li>
<ul>
<li>Tank 1</li>
<li>Tank 2</li>
</ul>
</li>
<li>Presse</li> //selected
<li>
<ul>
<li>Sub-leaf 1</li>
开发者_Python百科<li>Sub-leaf 2</li> //selected
<li>
<ul>
<li>test</li>
<li>test</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Any help is much appreciated, since this is a bit of a thorn in my eye :(
There is no such Selector to accomplish this task.
What I highly recommend you to do is to add ANYTHING as a flag to use when selecting your desired elements. add attribute, wrapper, ANYTHING YOU WANT, then the task will be as easy as it should be.
This may work: // not css selector
$(".treeView li:has('ul')").prev();
精彩评论