How do I make this loop all children recursively?

前端 未结 10 574
情书的邮戳
情书的邮戳 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:38

    If you have jquery and you want to get all descendant elements you can use:

     var all_children= $(parent_element).find('*');
    

    Just be aware that all_children is an HTML collection and not an array. They behave similarly when you're just looping, but collection doesn't have a lot of the useful Array.prototype methods you might otherwise enjoy.

提交回复
热议问题