0

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.

2
  • You could try setting it to null or 'unset' Commented Jan 19, 2021 at 18:46
  • If you could give working code snippet it would help us to help you better, Because JavaScript code part I see is not complete, selector, option, value variables are not initialized. Commented Jan 19, 2021 at 18:50

1 Answer 1

1

Well, el[i].style.color = '' should do the trick, if not, something is wrong with the elements selector.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.