javascript - jquery .not() is not working with live() - Stack Overflow

I am adding some dom with ajax in a page where i am trying to excluding seleted result by .not() but it

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:

  1. If i remove the .not() section of the code the selection is works fine with live().
  2. If i use .not() but replace live() with click() 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:

  1. If i remove the .not() section of the code the selection is works fine with live().
  2. If i use .not() but replace live() with click() 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 0
Add a ment  | 

3 Answers 3

Reset to default 8

As 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
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745146614a4613676.html

相关推荐

  • javascript - jquery .not() is not working with live() - Stack Overflow

    I am adding some dom with ajax in a page where i am trying to excluding seleted result by .not() but it

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信