$(document).on(“click”… not working?

前端 未结 5 510
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 02:34

Is there a well-known mistake I could be making here?

I\'ve got a script that\'s using .on() because an element is dynamically generated, and it isn\'t working. J

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 03:19

    This works:

    Click Me
    $(document).on("click","#test-element",function() { alert("click"); }); $(document).on("click","#start-element",function() { $(this).attr("id", "test-element"); });

    Here is the Fiddle

提交回复
热议问题