Remove inline CSS properties from an element with JavaScript/jQuery

Google Translate Icon

This post will discuss how to remove inline CSS properties from an element using JavaScript and jQuery.

The CSS property may have been directly applied using the HTML style attribute or using jQuery’s .css() method or direct DOM manipulation of the style property. Note, the solution does not remove the styles applied with a CSS class or with HTML <style> element.

1. Using jQuery

The standard method to set a CSS attribute is with the .css() method, which modifies the element’s style property. If you set the value of a style property to an empty string, it removes the property from that element. However, this leaves an empty style property on DOM.

JS


CSS


HTML



Edit in JSFiddle

 
Alternatively, you can get the style attribute using jQuery’s .prop() or .attr() method and then use the removeProperty() method to remove a property from it.

JS


CSS


HTML



Edit in JSFiddle

 
In case you want to remove the complete styling of the element, you can use jQuery’s .removeAttr() method, as shown below:

JS


CSS


HTML



Edit in JSFiddle

2. Using JavaScript

In pure JavaScript, you can use the removeProperty() method for removing a property from the style attribute of the element.

JS


CSS


HTML



Edit in JSFiddle

 
Alternatively, you can set the corresponding CSS property to an empty string, which removes it from the element.

JS


CSS


HTML



Edit in JSFiddle

 
If you want to remove the style attribute of an element completely, you can use JavaScript’s removeAttribute() method.

JS


CSS


HTML



Edit in JSFiddle

That’s all about removing inline CSS properties from an element using JavaScript and Query.

Rate this post

Average rating 4.77/5. Vote count: 26

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Tell us how we can improve this post?




Thanks for reading.

Please use our online compiler to post code in comments using C, C++, Java, Python, JavaScript, C#, PHP, and many more popular programming languages.

Like us? Refer us to your friends and help us grow. Happy coding :)



Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Do NOT follow this link or you will be banned from the site!