JavaScript operates class and style style code in detail

  • 2020-12-19 20:55:08
  • OfStack

Without further ado, I will post js code directly to you. The specific code is as follows:

<!doctype html>
<meta charset="utf-">
<title> Untitled document </title>
<div id="div" class="fontSize fontWeight" style="color:red">div Examples of text </div>
<button onclick="changeStyle()">changeStyle()</button>
function changeStyle()
var div = document.getElementById("div");
//div.className = "fontSize";
//div.className += " fontWeight";
// Removing a single class="" style 
//div.className = div.className.replace(/fontSize/,"");
// Delete all class="" style 
// delete style="" Single style in =,"blue");
// delete style="" All styles in 
// = "";

This is the complete explanation of class and style style code for JavaScript operations.

Related articles: