📜  获取和更改元素的类 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:23.493000             🧑  作者: Mango

代码示例2
const mssg = document.querySelector('p');//get the class of the p tag
console.log(mssg.getAttribute('class'));//the class is currently 'error'
mssg.setAttribute('class', 'success');//now the p tag's class is changed to 'success'
console.log(mssg.getAttribute('class'));//the new class of the p tag is 'success'