How can i get correct className from multiple classes in Vanilla Javascript

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;
<div class="one two three">
<div class="child-element">Child Element</div>

Source: JavaSript – Stack Overflow

December 3, 2021
Category : News
Tags: classname | javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.