JavaScript Add Class (in 3 Ways) - Tuto…
https://www.tutorialstonight.com/javascript-add-class
To add a CSS class using javascript follow the steps below: Select the element by its id or using a query selector. Use the classList property and the add() method to add the class name as an argument. For example: element.classList.add('newclass'). Alternatively, use the className property and append the class name with a space. For example: element.className += ' newclass'. Select the HTML element. Apply the classList property to it. Use the add () method to add the class and pass the class name as an argument.
Select the element by its id or using a query selector.
Use the classList property and the add() method to add the class name as an argument. For example: element.classList.add('newclass').
Alternatively, use the className property and append the class name with a space. For example: element.className += ' newclass'.
Select the HTML element.
Apply the classList property to it.
Use the add () method to add the class and pass the class name as an argument.
DA: 57 PA: 58 MOZ Rank: 57