【发布时间】:2018-11-27 14:29:29
【问题描述】:
假设我有这个字符串:
let string = '<h1 style="lots of class"> </h1><h2> <p style="bunch of class"> </p> <p style="bunch of class"> </p></h2>';
所以基本上它是一堆这样的元素,但在字符串中:
<h1 style="bunch of class"> </h1>
<h2>
<p style="bunch of class"> </p>
<p style="bunch of class"> </p>
</h2>
使用 jquery 或 vanilla javascript,如何从字符串中删除样式属性?
这个我已经试过了:
$(string).find('h1').removeAttr('style');
但它不起作用
【问题讨论】:
-
您需要删除所有样式还是只删除
h1样式? -
@KoshVery 所有元素的所有样式。基本上我真正想要的是所有元素的香草版本,没有任何属性或样式,只是纯粹的骨架。
-
我已经更新了我的答案以帮助您去除任何属性。
标签: javascript jquery html regex