How can I remove a style added with .css() function?

Viewed 1132492

I'm changing CSS with jQuery and I wish to remove the styling I'm adding based on the input value:

if(color != '000000') $("body").css("background-color", color); else // remove style ?

How can I do this?
Note that the line above runs whenever a color is selected using a color picker (ie. when the mouse moves over a color wheel).

2nd note: I can't do this with css("background-color", "none") because it will remove the default styling from the CSS files.
I just want to remove the background-color inline style added by jQuery.

21 Answers

2018

there is native API for that

element.style.removeProperty(propery)
let el = document.querySelector(element)
let styles = el.getAttribute('style')

el.setAttribute('style', styles.replace('width: 100%', ''))

you remove style using

removeAttr( 'style' );

You can use:

 $("#eslimi").removeAttr("style").hide();

Try

document.body.style=''

$("body").css("background-color", 'red');

function clean() {
  document.body.style=''
}
body { background-color: yellow; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button onclick="clean()">Remove style</button>

Related