Let's say we have
<p style="background-color: rgb(219, 51, 51); color: rgb(148, 87, 87);">
some text
</p>
The <style>
tag was added with code:
var el = document.querySelectorAll(selector);
for(var i=0;i<el.length;i++)
{
el[i].style[option] = value;
}
All i want to do is to remove single prop, for eg. color. I tried to use el[i].style.removeProperty('color');
, el[i].style.setProperty(option, 'initial');
and even el[i].style[option] = "";
, however none of this worked. I came up with an idea, that I can simply comment out prop with value in style tag, to look like this:
<p style="background-color: rgb(219, 51, 51); /* color: rgb(148, 87, 87); */">
some text
</p>
Do you have any idea how to write javascript function to comment out selected property with value from style tag? Any help would be appreciated.
Well, el[i].style.color = ''
should do the trick, if not, something is wrong with the elements selector.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.