How To Add A Class Name - W3Schools
Maybe your like
Learn how to add a class name to an element with JavaScript.
Add Class Click the button to add a class to me!Add Class
Step 1) Add HTML:
Add a class name to the div element with id="myDIV" (in this example we use a button to add the class).
Example
<button onclick="myFunction()">Try it</button><div id="myDIV"> This is a DIV element.</div>Step 2) Add CSS:
Style the specified class name:
Example
.mystyle { width: 100%; padding: 25px; background-color: coral; color: white; font-size: 25px;}Step 3) Add JavaScript:
Get the <div> element with id="myDIV" and add the "mystyle" class to it:
Example
function myFunction() { var element = document.getElementById("myDIV"); element.classList.add("mystyle");} Try it Yourself »Tip: Also see How To Toggle A Class.
Tip: Also see How To Remove A Class.
Tip: Learn more about the classList property in our JavaScript Reference.
Tip: Learn more about the className property in our JavaScript Reference.
❮ Previous Next ❯ ★ +1 Sign in to track progressTag » Add Div On Click Javascript
-
Add Click Event On Div Tag Using JavaScript - Html - Stack Overflow
-
Create An Element With OnClick Event Listener Using JS | Bobbyhadz
-
HTML DOM Document CreateElement() Method - W3Schools
-
JQuery Append() Method - W3Schools
-
HTML DOM Element Click() Method - W3Schools
-
How To Append HTML Code To A Div Using JavaScript - GeeksforGeeks
-
How To Add A Number To A Div After Clicking A Button In JavaScript
-
How To Add A Click Event Listener On Div Tag Using JavaScript?
-
Onclick Append Class To Div In Javascript Code Example
-
How To Append Or Add Text To A DIV Element Using JavaScript
-
JavaScript – Insert Element After Specific Div Element - Tutorial Kart
-
Add New Div While Click A Button Using Javascript Or Jquery
-
Javascript Add Button To Div Code Example
-
HTML Button Onclick – JavaScript Click Event Tutorial