tags:

views:

37

answers:

1
//html structure
    <div id='outer'>
       <div id='inner'>
       </div>
    </div>

I am adding some data to inner element like

$('#inner').data('_key','_someValue');

Now some time in future, I am clearing text of outer element.

$('#outer').empty().html('some thing new');

I am clearing div's text using empty(), I read that empty() removes all events bound on children elements.

My question is, doe the empty function also remove data from element or we have to do it ourselves like $('#inner').data('_key',null) before removing element from DOM or its done automatically by empty().

+2  A: 

From http://api.jquery.com/empty/

If we had any number of nested elements inside , they would be removed, too. Other jQuery constructs such as data or event handlers are erased as well.

So, from what I understand all data, also the data associated with the child elements will be removed.

Obalix