我正在使用jquery.load()加载外部html文件。外部文件具有内联css,并在主页面中呈现。如何禁用该css或者可以立即完全删除css。
我见过像这样的解决方案
removeClass()
removeAttr()
但是使用这些方法我需要明确地提供每个属性。
答案 0 :(得分:0)
下面将过滤/搜索具有style
属性的元素并将其删除:
$('#content').filter(function() {
var attr = $(this).attr('style');
return typeof attr !== typeof undefined && attr !== false;
}).removeAttr('style');
<强>来源:强> removeAttr,filter,hasAttr
编辑:each
不需要,只需从查询中删除所有style
编辑2:由于OP没有指定要获取的元素并且根据他的评论,这段代码应该正确地执行:
$('#preview [style]').removeAttr('style');