开发者

How to bind events in Jquery for an element created after document load?

I have a set of list items in unordered lists that I bind the anchors inside them to fire when clicked. The thing is: Some ul's are created (via ajax) when I click on some of the li's created in the first place, binded in the jQuery's document.ready. And I want t开发者_如何学Chis li's that are created dynamically to fire as well. Can I do that?

Well, I hope you get what i mean...


Check out live() method

Use it the same way as bind(), ie :

$('.class').live('click', function() { 
     alert('bla');
   }
);


I think you are looking for live().


The live() event will work on all ul elements even if you create them after you bind the live method to them. Like so:

$('ul').live('click', function() {
  // your code here...
}

See the info on live here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜