Appending HTML w/click event using jQuery

前端 未结 4 2225
小蘑菇
小蘑菇 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:10

    What about :

    $("#myID").click(
      function () {
         var someText = "my dynamic text";
         var newDiv = $("
    ").append(someText).click(function () { alert("click!"); }); $(this).append(newDiv); } )

提交回复
热议问题