jQuery click event, after appending content

后端 未结 6 2046
庸人自扰
庸人自扰 2020-12-05 18:21

Wondering why the example below doesn\'t work?

Load the list

    6条回答
    •  余生分开走
      2020-12-05 18:43

      .live is deprecated as of 1.7. Try this (jquery 2.1.4):

      Html:

      Load the list
      
      

        JQuery:

        $(document).ready(function() {
        
         $('#load_list').click(function() {
           $('ul').html("");    
        
           $("
      • ", { "class" : "someClass", text: "Click here", click: function() { alert($(this).text()); } }).appendTo('ul'); }); });
      • or something like this (but I didn't find how to attach click to the anchor):

        $(document).ready(function() {
         $('#load_list').click(function() {
           $('ul').html("");
        
           $('
      • Click here
      • ').on({ click: function() { alert("hoi"); } }).appendTo("ul"); }); });

      提交回复
      热议问题