jquery binding events to dynamically loaded html elements

前端 未结 4 763
你的背包
你的背包 2020-12-06 13:18

using jquery we can attach event handlers to the elements present in page, this is done inside document.ready() function. Now my difficulty is i have some elements like link

4条回答
  •  难免孤独
    2020-12-06 13:52

    Then you'll want to use .live(). Have a look at http://api.jquery.com/live/.

    Example:

    $('a').live('click', function() {
      // Do something useful on click.
    });
    

    In the example above, any A elements, whether already existing or loaded after the document is loaded, will trigger the click event.

提交回复
热议问题