I have a parent element with a single child element. I would like to get return only the parent element’s classname based on its classname. That means now in the console log, i getting 3 classes. But only want ‘one’ here. Because the ‘parent’ variable is targetted the class ‘.one’. Hopes someone can help me on this. If you did’nt understand ask me, so that i’ll come up with more details. Thanks in advance.
let parent = document.querySelector(".one"); let correctClass = parent.className; console.log(correctClass);
<div class="one two three"> <div class="child-element">Child Element</div> </div>
Source: JavaSript – Stack OverflowDecember 3, 2021