Search code examples
jquerycssprintingstylesheet

Print stylesheet precedence


I have inherited some legacy code which generates a ton of inline styles.

The client requires a print stylesheet which i am not sure will override the inline styles.

Assume not.

Would there be a way with jQuery to rip out all the inline styles whilst preserving the HTML structure prior to the print CSS being applied?


Solution

  • The client requires a print stylesheet which i am not sure will override the inlien styles.

    No it won't override unless there is !important keyword used in the inline styles.

    You can use the jQuery's removeAttr method to remove inline styles like:

    $('selector').removeAttr('style');
    

    You can use the asterisk (*) in the selector to remove any inline styles from all elements but of course this will be slower unless you are sure about which elements to remove the style from.