Javascript删除没有给定ID的样式属性
如何从中删除整个样式Javascript删除没有给定ID的样式属性,javascript,jquery,Javascript,Jquery,如何从中删除整个样式 <div class="style1 style2" style="width:200px; color:red"></div> 到 在div中没有ID并且无法添加ID? 没有ID我无法使用getElementById 您可以提供帮助吗?您可以使用querySelectorAll查询所需的元素,然后使用removeAttribute删除样式属性 函数removeStyle(){ const elem
<div class="style1 style2" style="width:200px; color:red"></div>
到
在div中没有ID并且无法添加ID?
没有ID我无法使用getElementById
您可以提供帮助吗?您可以使用
querySelectorAll
查询所需的元素,然后使用removeAttribute
删除样式属性
函数removeStyle(){
const elements=document.queryselectoral(“div.style1.style2”);
elements.forEach(element=>{
元素。removeAttribute('style')
})
}
测试
删除Style
是您的朋友。请尝试document.querySelector('.style1').setAttribute('Style','')代码>访问特定元素的方式取决于更高级别的用例。页面中任何具有样式的元素
,只有一个具有该类的特定元素等。提供更具体的详细信息和详细信息。还需要花几分钟的时间来阅读伟大的支持!
<div class="style1 style2"></div>