Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove style attributes from string

I'm trying to remove all style attributes from a string (and not an object), in JavaScript or jQuery.

Example

var html = "<p style="color:red">my text</p>";

And I want to obtain this:

<p>my text</p>

Is it possible to do it without calling the functions that we can call on objects (as removeAttr)?

Thanks

like image 908
user Avatar asked Dec 05 '25 10:12

user


1 Answers

If you are not looking to use JavaScript or jQuery objects, have you tried using regular expressions?

This answer to a previous question shows a php version that can be adapted to JavaScript using the replace function.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!