getElementById() wildcard

后端 未结 6 2229
北荒
北荒 2020-11-28 11:37

I got a div, and there i got some childnodes in undefined levels.

Now I have to change the ID of every element into one div. How to realize?

I thought, becau

6条回答
  •  佛祖请我去吃肉
    2020-11-28 12:26

    I don't think so wildcards are allowed in getelementById. Instead you can have all the child nodes of your respective DIV using:

    var childNodeArray = document.getElementById('DIVID').childNodes;
    

    This'll give you an array of all elements inside your DIV. Now using for loop you can traverse through all the child elements and simultaneously you can check the type of element or ID or NAME, if matched then change it as you want.

提交回复
热议问题