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

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -