JQuery: determine that the DOM has changed

edit: change the .ready () prompt to Matt's suggestion.

I use jQuery to configure some of these things:

$(function ()
{
     $('.myThing').each(function() {

         ... configure it ...

     });
});

My problem is that a new element is added to the DOM after calling .ready (). No configuration is performed for these items.

For simple things, such as binding a click event, .live () does the job. But for more complex things, I did not find a good solution.

Is there an event when the DOM changes? Or, in particular, when new elements are added to the DOM?

Edited: A preliminary solution using livequery is as follows:

$(function ()
{
    $.fn.configureIt = function()
    {
        ... configure it ...
    }
});
$('.myThing').livequery(function () {
    $(this).configureIt ()
});

: livequery . DOM . , , . , , livequeries IE6, .

, " " . JavaScript , JavaScript, JavaScript, HTML . JavaScript .

, , , , DOM AJAX , :

$('.stuff').load(loadUrl, postData, function() {
    $(this).trigger('contentLoaded');
    // among other stuff
});

.

$('*').live('contentLoaded', function() {
    $('.myThing', this).configureIt();
});

. , - ( , ), , , , .

+3
2

livequery . , , , .

+1

.live(), . delegate(). API - - , , , .live() .

0

Source: https://habr.com/ru/post/1751418/


All Articles