jQuery click handler function does not fire on element added after DOM load

后端 未结 2 1100
孤独总比滥情好
孤独总比滥情好 2021-01-13 06:12

I believe I could do this with .live but that method is deprecated. Here\'s the issue:

I have a click handler function that should fire on any element with the class

2条回答
  •  执笔经年
    2021-01-13 06:49

    You need to use Event delegation

    jQuery(document).on('click','.myClickEl', function() { 
        var formText='This is some text to paste';
        jQuery(this).parent().next('textarea').val('');
        jQuery(this).parent().next('textarea').val(formText);
    });
    

提交回复
热议问题