I am adding some dom with ajax in a page where i am trying to excluding seleted result by .not()
but its not working for me.
Here is a simple example:
HTML:
<div class="list-item">
<span class="item-title">Some title</span>
<span class="edit fr"><a href="Edit link">Edit</a></span>
<span class="trash fr"><a href="#trashit" rel="trash">Trash</a></span>
<span class="live fr active"><a href="#liveit" rel="publish">Live</a></span>
<span class="draft fr"><a href="#draftit" rel="draft">Draft</a></span>
</div>
jQuery:
jQuery('.list-item span a').not('.list-item span.edit a').live('click', function(){
//do stuff
});
Observation:
- If i remove the
.not()
section of the code the selection is works fine withlive()
. - If i use
.not()
but replacelive()
withclick()
the code works.
But i need to run the .not()
(exclude the .edit
class) with the live();
(including dom with ajax)
Thanks in advance!
I am adding some dom with ajax in a page where i am trying to excluding seleted result by .not()
but its not working for me.
Here is a simple example:
HTML:
<div class="list-item">
<span class="item-title">Some title</span>
<span class="edit fr"><a href="Edit link">Edit</a></span>
<span class="trash fr"><a href="#trashit" rel="trash">Trash</a></span>
<span class="live fr active"><a href="#liveit" rel="publish">Live</a></span>
<span class="draft fr"><a href="#draftit" rel="draft">Draft</a></span>
</div>
jQuery:
jQuery('.list-item span a').not('.list-item span.edit a').live('click', function(){
//do stuff
});
Observation:
- If i remove the
.not()
section of the code the selection is works fine withlive()
. - If i use
.not()
but replacelive()
withclick()
the code works.
But i need to run the .not()
(exclude the .edit
class) with the live();
(including dom with ajax)
Thanks in advance!
Share Improve this question asked Aug 19, 2011 at 20:40 SisirSisir 2,8047 gold badges55 silver badges86 bronze badges 03 Answers
Reset to default 8As per the .live()
docs:
DOM traversal methods are not supported for finding elements to send to
.live()
. Rather, the.live()
method should always be called directly after a selector, as in the example above.
So, add the class exclusion to the selector:
jQuery('.list-item span:not(.edit) a').live('click', function(){
//do stuff
});
Try
$('.list-item span:not(.edit) a').live(...);
As someone else pointed out, DOM traversal is not supported for live. live has some other restrictions too, check the doc.
jQuery('.list-item').filter(function(){
return $(this).not("span.edit a")
})
.live('click', function(){
//do stuff
});