Question #467
Submitted by Answiki
on 05/19/2021 at 08:02:11 PM UTC
How to add class using vanilla js?
Merged questions
Answer
Submitted by Answiki
on 05/19/2021 at 08:02:53 PM UTC
In JavaScript, the simplest way to add a class is to use the method .add() on the property .classList:
var element = document.getElementById('ID');
element.classList.add('myClass');
Answer by Answiki on 05/19/2021 at 08:02:53 PM
In JavaScript, the simplest way to add a class is to use the method .add() on the property .classList:
var element = document.getElementById('ID');
element.classList.add('myClass');
Question by Answiki 05/19/2021 at 08:02:42 PM
How to add a class to a given element in JavaScript?
Question by Answiki 05/19/2021 at 08:02:26 PM
How to add class using pure JavaScript?
Question by Answiki 05/19/2021 at 08:02:21 PM
How to add class using JavaScript?
Question by Answiki 05/19/2021 at 08:02:11 PM
How to add class using vanilla js?
Answer by Answiki on 05/19/2021 at 08:02:02 PM
In JavaScript, the simplest way to add a class is to use the method .add() on the property .classList:
var element = document.getElementById('ID');
element.classList.add('myClass');
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 12258 | en | https://en.ans.wiki/467/how-to-add-class-using-vanilla-js | 11 |
Icons proudly provided by Friconix.