如何删除符合特定条件的所有Div的样式?

时间:2014-03-20 10:16:38

标签: javascript jquery html css

我有以下HTML结构=>

<span style="font-size:13px;">
<div style="margin-top:14pt;margin-bottom:1em;"><br>

<font size="1"><span style="font-size:12px;"><b>Name:</b></span></font><font size="1"><span style="font-size:12px;"> pratikJj jj</span></font></div>
<div style="margin-top:14pt;margin-bottom:1em;"><font size="1"><span style="font-size:12px;"><b>Email:</b> <a target="_blank" href="redir.aspx?C=AqQ9qrS3S0CCUr8wYx3QUu0HmT-cF9EI3kjBzIy3J26HoWKecGaL2VVHKtRt0q8meK1S8kDowtw.&amp;URL=mailto%3apratik.joshi%40aressindia.net">pratik.joshi@aressindia.net</a></span></font></div>
<div style="margin-top:14pt;margin-bottom:1em;"><font size="1"><span style="font-size:12px;"><b>Phone Number:</b></span></font><font size="1"><span style="font-size:12px;"> 919999999999</span></font></div>
<div style="margin-top:14pt;margin-bottom:1em;"><font size="1"><span style="font-size:12px;"><b>Name Of Facility:</b> sdsd</span></font></div>
<div style="margin-top:14pt;margin-bottom:1em;"><font size="1"><span style="font-size:12px;">&nbsp;</span></font></div>
</span>

这就是我想做的事情=&gt;

如果div包含以下样式

margin-top:14pt;margin-bottom:1em;

然后样式应为空白或例如style =&#34;&#34;

4 个答案:

答案 0 :(得分:7)

尝试使用attribute contains selector

$('div[style*="margin-top:14pt;margin-bottom:1em;"]').removeAttr("style");

答案 1 :(得分:0)

如果你在div上有课程会更容易(更清洁)吗?

然后基本上适应Rajaprabhu提供的相同答案:

$(".className").removeAttr('style');

答案 2 :(得分:0)

如果我是你,我会将样式移动到CSS和类,然后使用以下语句:getElementsByClassNameclassList.remove。 您可以找到更多信息herethere

答案 3 :(得分:0)

如上所述,我会从HTML标记中移动所有样式,而不是将它们放入CSS中。然后利用JavaScript / jQuery选择器。

另请注意:HTML5不支持<font>标记。