How can I force the DOM to override Javascript / jQuery?

I am adding HTML dynamically to a web page, and I also use jQuery to manage files.

When I add HTML, jQuery ignores its existence.
For example:

$("td.elementToClick").click(...

Will work fine with jQuery. But if somewhere in the code I add:

$("tr#myRowToAppend").append("<td class="elementToClick>...</td>");

jQuery will ignore this new element if I click on it.

Since jQuery binds events after the page has finished loading, I need one of two solutions: - Make the DOM refresh the page without changing the current layout (I don't want the update, so location.reload () is out of the question). - Force jQuery to add this new element to this internal event dispatcher.

I do not want to use onclick="blabla()", I really need to use jQuery.

How can i do this?

+3
2

, jQuery live. : " (, ) . ".

liveQuery, , .

+9

live() .

IE , IE DOM.

SO , / dom dom , IE.

, live DOM, , clone (true), , :

$("body").append('<div id="one"></div>");

$("#one").mouseover(function(){});

$("body").append( $("#one").clone(true).attr('id','two') );
+2

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


All Articles