I was wondering if this is possible.
There's this element
<div id="sample_id" style="width:100px; height:100px; color:red;">
So I want to remove width:100px; and height:100px;
the result would be
<div id="sample_id" style="color:red;">
Any help would be apprreciated. :)
Use the removeAttribute() method to remove all styles from an element, e.g. box. removeAttribute('style') . The removeAttribute method will remove the style attribute from the element.
You can remove CSS style properties from an element by setting the property to a null value, e.g. box. style. backgroundColor = null; . When an element's CSS property is set to null , the property is removed from the element.
You can edit style with pure Javascript. No library needed, supported by all browsers except IE where you need to set to ''
instead of null
(see comments).
var element = document.getElementById('sample_id'); element.style.width = null; element.style.height = null;
For more information, you can refer to HTMLElement.style documentation on MDN.
var element = document.getElementById('sample_id'); element.style.removeProperty("width"); element.style.removeProperty("height");
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