JQuery html () removes all data attached to replaceable elements?

I am showing a tabbed interface using jQuery. When you click the tab, the ajax call replaces all the html from the element with the $(".content")new html, using something like

$(".content").html(response);

When I do this, are all jquery events and functions that are attached to the elements inside the .contentdiv deleted? Is it possible to resume these events and functions after replacing the HTML? If I click on the tabs 324523452354 times, will it duplicate jQuery data each time?

+3
source share
3 answers

Yes. They will be deleted. You can use a live event to join elements that do not yet exist.

 $(".myElementClass").live("click", function (e) {
         e.preventDefault();
         //do stuff
});

myElement , DOM.

+2

HTML , , , DOM. , :

<div id="mine">
  <ul>
    <li>One thing</li>
  </ul>
</div>

:

$('div#mine').html("hey");

HTML :

<div id="mine">
  hey
</div>

, , . , jQuery.live(), , , . DOM, , , .

0

All Articles