Appending HTML w/click event using jQuery

前端 未结 4 2223
小蘑菇
小蘑菇 2021-02-20 15:59

I want to append some HTML inside this div, and the HTML has to have a click event on it also.

    

hello, world!

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-20 16:32

    Andrew solve this problem to me! But .live is deprecated in the recent versions of jquery (as of 1.7). Use .on or .delegate on top.document to bind these events types. See:

    $(document).on(".myClass", "click", function(){
        $(this).after("
    Another paragraph!
    "); });

    Congrats my friend!

提交回复
热议问题