How do I make this loop all children recursively?

前端 未结 10 614
情书的邮戳
情书的邮戳 2020-12-24 12:06

I have the following:

for (var i = 0; i < children.length; i++){
   if(hasClass(children[i], \"lbExclude\")){
       children[i].parentNode.removeChild(ch         


        
10条回答
  •  天命终不由人
    2020-12-24 12:54

    if items are being created in a loop you should leave a index via id="" data-name or some thing. You can then index them directly which will be faster for most functions such as (!-F). Works pretty well for 1024 bits x 100 items depending on what your doing.

    if ( document.getElementById( cid ) ) {
     return;
    } else {
      what you actually want
    }
    

    this will be faster in most cases once the items have already been loaded. only scrub the page on reload or secure domain transfers / logins / cors any else and your doing some thing twice.

提交回复
热议问题