Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

typescript - How to remove the all child classes from the parent in JavaScript

I want to remove the bootstrap child classes row from the parent element .But not working for me showing the errors.

the code is

 if(document.getElementById(v)){
        console.log(v)
        document.getElementById("mapper").removeChild(document.getElementsByClassName("row"))
       //document.getElementById("mapper").classList.remove('row');
     

      }
question from:https://stackoverflow.com/questions/66061991/how-to-remove-the-all-child-classes-from-the-parent-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Considering element with id="mapper" is your parent element and you want to remove children's row class. Try this :

var mapper = document.getElementById("mapper").children;
for(i=0; i<mapper.length;i++) {
   mapper[i].classList.remove("row")
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...