views:

60

answers:

2

Hi,

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?

+2  A: 

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.

Sarfraz
A: 

Rather than using jquery you can easily achive using CSS by creating style sheet and assigne media = "print"

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

Check this : Pritnt Style sheet

Pranay Rana
Yes, but there is no garantee that this will override the inline styles.
kbok
if you use media = "print" it must work show me example in which its wont work
Pranay Rana
I assumed the inline styles owuld take precedence even if the media was set to print.Would be nice if they weren't but would need to see evidence of this.
RyanP13