Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery 'live' for selector?

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.

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

Is this even possible?

like image 524
SaphuA Avatar asked Nov 06 '22 13:11

SaphuA


1 Answers

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') });
like image 66
user113716 Avatar answered Nov 12 '22 15:11

user113716