javascript - Jquery each() function -
given list
<ul> <li>aaa</li> <li>sss</li> <li>ddd</li> </ul> js code:
$(document).ready( function () { $("ul li").each( function () { $("ul").empty(); alert( $(this).text() ); }); }); this code returns every element normally, why? why list not cleared @ first iteration?
the unordered list indeed cleared in first iteration, list items still referenced jquery object created $("ul li").
they may not part of dom anymore, still exist in memory, , can still access , manipulate them.
Comments
Post a Comment