Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript删除没有给定ID的样式属性_Javascript_Jquery - Fatal编程技术网

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>