Monday, September 29, 2008

[jQuery] removing style tags and script tags

Hello all,

I have a webapp displaying email which can sometimes contain HTML
message bodies. I use jquery's .ajax method to grab an HTML message
body and then put it into a div tag. Problem is if the HMTL contains
style or script tags I get unwanted results.

I've tried $( html ).find( 'style' ).remove(). This will remove the
the actual <style> and </style> tags but still leaves the style text
itself inside. I tried several variations but I just can't seem to
get this to remove the actual style text with the style tags. Any way
to do this or will I have to do a bunch of custom search and replaces?

Thanks in advance,
cRRRum

No comments: