How to change or toggle class name of a child element from a parent element using javascript?

`<div class="box-5" id="firstselectionbox">
            <button class="firstselection highlighted" id="constructionbutton"onclick="toggleclassbox2(this)"value=1>Construction</button>
            <button class="firstselection" id="interiorbutton" onclick="toggleclassbox2(this)"value=2>Interiors</button>
        </div>

function toggleclassbox2(elm) {
      var helement = document.querySelector("#firstselectionbox");
      console.log(helement.childNodes);
} ` 

The last line helement.childNodes gives me the child elements, but I am unable to get the class List of child elements or toggle them. Please help.

40 thoughts on “How to change or toggle class name of a child element from a parent element using javascript?”

  1. 509877 466425Previously you must have highly effective internet business strategies get you started of getting into topics suitable for their web-based organization. educational 555079

    Reply
  2. 886241 588692Pretty section of content material. I just stumbled upon your website and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way Ill be subscribing to your feeds and even I achievement you access consistently quickly. 976424

    Reply

Leave a Comment