开发者

JQuery 'live' for selector?

开发者 https://www.devze.com 2022-12-31 02:27 出处:网络
I would like to have the same behaviour \'live\' has, but without using events. Is this possible? I need this because I\'m using a different javascript file that creates some elements to which I need

I would like to have the same behaviour 'live' has, but without using events. Is this possible? I need this because I'm using a different javascript file that creates some elements to which I need to append css classes.开发者_如何学Go

The following code should execute once such an element is added to the dom: $(".myClass").addClass("myNewClass");

Is this even possible?


The liveQuery plugin is capable of this.

http://brandonaaron.net/code/livequery/docs

From the docs: Live Query also has the ability to fire a function (callback) when it matches a new element and another function (callback) for when an element is no longer matched.


EDIT:

This would be a code solution using livequery.

$('.myClass').livequery(function() { $(this).addClass('myNewClass') });


Perhaps I don't understand what you are asking, but if you are using jQuery, why can you not use an event driven update?

The liveQuery solution Patrick suggests (which will work just fine) uses events in the background, just like 'live'.

0

精彩评论

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