Click the button to add the "mystyle" class to DIV. I am a DIV element
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<style>
.mystyle { margin: 20px; width: 300px; height: 50px; background-color: coral; color: white; font-size: 25px;
}
</style>
</head>
<body>
<p>Click the button to add the "mystyle" class to DIV.</p>
<button onclick="myFunction()">Try it</button>
<div id="myDIV">
I am a DIV element
</div>
<br>
<script>
function myFunction() { document.getElementById("myDIV").classList.add("mystyle");
}
</script>
</body>
</html>
How to Use of the class attribute in an HTML document - | HTML Global Attributes |
How to add Add multiple classes to one HTML element | HTML Global Attributes |
How to use JavaScript to add a yellow background color to the first element with class="example" (index 0) | HTML Global Attributes |
How to use JavaScript to add the "mystyle" class to an element with id="myDIV" | HTML Global Attributes |
HTML accesskey Attribute | HTML Global Attributes |
HTML class Attribute | HTML Global Attributes |
HTML contenteditable Attribute | HTML Global Attributes |
HTML data-* Attributes | HTML Global Attributes |
HTML dir Attribute | HTML Global Attributes |
HTML draggable Attribute | HTML Global Attributes |
HTML enterkeyhint Attribute | HTML Global Attributes |
HTML hidden Attribute | HTML Global Attributes |
HTML id Attribute | HTML Global Attributes |
HTML inert Attribute | HTML Global Attributes |
HTML inputmode Attribute | HTML Global Attributes |
HTML lang Attribute | HTML Global Attributes |
HTML popover Attribute | HTML Global Attributes |
HTML spellcheck Attribute | HTML Global Attributes |
HTML style Attribute | HTML Global Attributes |
HTML tabindex Attribute | HTML Global Attributes |
HTML title Attribute | HTML Global Attributes |
HTML translate Attribute | HTML Global Attributes |
HTML Global Attributes | HTML Global Attributes |
Type
: |
html |
Category
: |
Web Tutorial |
Sub Category
: |
HTML Global Attributes |
Uploaded by
: |
Admin |