Alternative to jquery live that can work

后端 未结 3 2041
悲&欢浪女
悲&欢浪女 2020-12-10 15:23

I have this simple code. http://jsfiddle.net/borth/BmEZv/ If you click on the link once, it works fine. If you click on it a second time, it doesn\'t work. Due to the html b

相关标签:
3条回答
  • 2020-12-10 16:10

    Following @Dhofca this really worked. I am just showing an example which I tried with 'this' keyword.

    $(document.body).on('click', ".query-result table tr", function () {
        var el = $(this);
        el.closest('table').find('tr').removeClass('dotted');
        el.addClass('dotted');
    });
    
    0 讨论(0)
  • 2020-12-10 16:15

    .on() can be used with or without delegation, below is an example of on() using delegation.

    $("#ABC").on('click', ".OpenPopup", function(e){
    

    http://jsfiddle.net/BmEZv/1/

    0 讨论(0)
  • 2020-12-10 16:16
    $(document).ready(function(){
            $(document.body).on('click', ".OpenPopup", function(e){
                alert('test .OpenPopup');
                // do something
                return false;
            });
            $(document.body).on('click', ".EditIcon", function(){
                alert('test .EditIcon');
                // do something
                $("#ABC").html('<div class="EditIcon OpenPopup" pwidth="800" pheight="500" ptitle="Edit Text">click here again</div>');
            });
        });
    
    0 讨论(0)
提交回复
热议问题