If I set a CSS value on a specific element using:
$('#element').css('background-color', '#ccc');
I want to be able to unset that element-specific value and use the cascaded value, along the lines of:
$('#element').css('background-color', null);
But that syntax doesn't seem to work – is this possible using another syntax?
Edit: The value isn't inherited from the parent element – the original values comes from an element-level selector. Sorry for any confusion!
removeClass(). removeAttr('style');
There is a property called all that is being proposed for resetting all CSS properties for a given element to certain CSS-wide values - the value you want to use would be unset , which resets a property to either its inherited value if it inherits by default, or otherwise, its initial value.
To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.
If you want to remove a specific style tag, you can add a class (or id) to it and then use remove() to remove that class.
From the jQuery docs:
Setting the value of a style property to an empty string — e.g.
$('#mydiv').css('color', '')
— removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's.css()
method, or through direct DOM manipulation of thestyle
property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or<style>
element.
I think you can also do:
$('#element').css('background-color', '');
That's what I used to do a long time ago for the display
property in plain-old-javascript to show/hide a field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With