JQuery: targeting elements added with * non-jQuery * AJAX before Javascript events fire? Besides the realm of the living ()?

Work on a Wicket application that adds markup to the DOM after onLoad via the built-in AJAX Wicket to autocomplete the widget. We have IE6 crashes, which means I need to move the markup that goes into it, and I'm trying to avoid javascript Wicket interference ... blah blah blah ... this is what I'm trying to do:

  • New markup arrives at the DOM (I don't have access to the callback)
  • Somehow I know this, so I run my code.

I tried this, hoping that the new tags will trigger onLoad events:

 $("selectorForNewMarkup").live("onLoad", function(){ //using jQuery 1.4.1
    //my code
});

... but got educated that onLoad only works when the page loads. Is there another event when elements are added to the DOM? Or another way to sense the changes in the DOM?

Anything I've run into similar problems with new markup additions, they have access to the callback function on .load () or the like, or they have a real javascript event to work and live () works fine.

Is this a dream dream?

+3
source share
2 answers

.live()doesn't work like that, this is a common misconception. .live()creates an event handler in the root of the DOM and expects events to bubble before it. If the selector matches the event's target point, the .live()associated event will light.

- , , , DOM.

, .

livequery, livequery( matchedFn ).

- :

$('#myID').livequery(function() { $(this).offset()...stuff });
+1

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


All Articles