How to remove inherited styles using jQuery?
Hello guys I have a DIV that I got passed trought a js function :
function print(divId) {
var det = document.getElementById(divId);
$(divId).removeClass(); ..
$(divId).removeAttr(); ..
var mywindow = window.open(' ', 'Print');
mywindow.document.write('<html><head><title>Account Detail</title>');
mywindow.document.write('<link href="../../css/reset-min.css" rel="stylesheet" type="text/css" />');
mywindow.document.write('</head><body>');
mywindow.document.write(det.innerHTML);
mywindow.document.write('</body></html>');
}
I've been tryed with some jQuery functions like the showed above, buy it not works because styles are inherits from css templates, so开发者_如何学JAVA How can I remove completly the CSS and Styles attributes completly.. I hear about YUI Reset http://developer.yahoo.com/yui/reset/ but I don't know how to use it in a new Windows Popup
Thanks!
Just use the .css(
jQuery method and remember to append !important if necessary to enforce overriding.
This will effectively set the style="
attribute on the element.
Create a CSS class that overrides all the inherited properties and then just remove all the classes from the div and add the css class that overrides everything.
I think you will need to clone the target node to remove the attributes for every element therein:
var det = document.getElementById(divId);
if (det) {
det = det.cloneNode();
$(det).removeAttr("class").removeAttr("style").find("*").each(function(i, elem) {
$(elem).removeAttr("class").removeAttr("style");
});
// …
}
Will these help:
$("link[rel=stylesheet][class=must-remove-when-printing]").remove();
And:
$("*[class]").removeAttr("class");
$("*[style]").removeAttr("style");
精彩评论