开发者

How do I use jQuery .live to call a method on an element when it is created?

开发者 https://www.devze.com 2022-12-20 15:11 出处:网络
I have a page with some inputs of the class \'foobar\', and I call a method on each开发者_StackOverflow of them.

I have a page with some inputs of the class 'foobar', and I call a method on each开发者_StackOverflow of them.

$("input.foobar").css('color', 'red');

and I am adding more .foobar inputs to the page with javascript.

How can I use jQuery live (or any other method), to watch the page for the creation of new elements that match "input.foobar" and perform my css call on them as soon as they are added to the DOM?

I am confused because live seems to work by adding an event handler, but I do not know how to describe the element creation event.

Thanks.


the livequery plugin was made to do this specifically: http://docs.jquery.com/Plugins/livequery


See this thread.It will give you some idea.

Jquery Click event of <a> tag added at run time doesn't get fired


See Mutation event types. I am not sure about the support in various browsers.

DOM Mutation Events

0

精彩评论

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

关注公众号