jQuery with elements generated dynamically

前端 未结 6 1562
旧巷少年郎
旧巷少年郎 2021-01-19 16:14

I\'ve been working with jQuery for a pair of weeks and I\'ve noticed it works fine with objects that are in the original HTML document, but when I generate a new element usi

6条回答
  •  盖世英雄少女心
    2021-01-19 16:50

    If you have jQuery 1.3 or later, try using live for adding events to dynamically generated elements:

    $('.whatever').live("click", function() {
      alert("ALERT!");
    });
    

提交回复
热议问题