jQuery click event, after appending content

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

Wondering why the example below doesn\'t work?

Load the list

    6条回答
    •  感动是毒
      2020-12-05 19:07

      Because the elements that you are appending do not exist when you define the the click handler, they are created dynamically. To fix this you can use the delegate() method from jQuery.

      $('ul').delegate('a','click',function() {
          // your code here ...
      });
      

      Online example: http://jsfiddle.net/J5QJ9/

    提交回复
    热议问题