To add a class to an element using JavaScript, you can use the classList.add() method. Here's an example:

HTML:

<div id="myDiv">Hello World</div>

JavaScript:

var myDiv = document.getElementById("myDiv");
myDiv.classList.add("myClass");

This code adds the class "myClass" to the "myDiv" element.

i want addclass to class by javascript

原文地址: https://www.cveoy.top/t/topic/bG3C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录