views:

21

answers:

2

Hi all,

I was wondering if there was any way of removing unwanted style attributes from objects (p, ul, li etc), as for some reason my client has decided to copy/paste information from word into a wysiwyg and doesn't bother removing the crap that comes along with it, I was wondering if jquery could do this?

Here's an example of the outputted code (which varies obviously depending on what they've copied/pasted from)

<ul style="list-style-type: disc;">
<li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px 'Lucida Grande';">Residential Class 1/ New Buildings</li>
<li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px 'Lucida Grande';">Residential Class 1/ Best Renovation</li>
<li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px 'Lucida Grande';">Resorts, including apartments and aged care</li>
<li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px 'Lucida Grande';">Public or Commercial Buildings</li>
<li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px 'Lucida Grande';">Interior Fitout – Residential</li>
<li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px 'Lucida Grande';">Interior Fitout – Commercial</li>
<li style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 21.0px; font: 12.0px 'Lucida Grande';">Outdoor Timber – Stand alone structures</li>
</ul>

Thoughts?

I've tried using strip_tags in php (and allow for p tags) but it brings the styles along with it.. even if this is possible in php that would be good :)

+1  A: 

Just use the css method:

$("ul").css("list-style-type", "");
$("li").css("margin", "");
$("li").css("line-height", "");
$("li").css("font", "");
GenericTypeTea
+1  A: 

You can remove all the style by :

$("#myelem").removeAttr("style");

If you want a specific styles to remove see the answer of user147767 in this topic:

http://stackoverflow.com/questions/955030/remove-css-from-a-div-using-jquery

He wrote a great function!

Haim Evgi
This will remove the entire style, not just an individual attribute as per the question.
GenericTypeTea
i know i update the answer :)
Haim Evgi