1

I want to override my inline css by using dom and when I am going for !important , color doesn't work.

 componentDidMount(){
    document.getElementById("para").style.color = "red !important"
  }

Here is the default example , why it doesn't work ?

I am also giving link : https://codesandbox.io/s/react-draft-wysiwyg-editor-ppctk

1

1 Answer 1

1

Regardless of whether using React syntax or not, attribute !important value has to be set with a method and cannot be assigned directly. Here are a few examples:

// Specific old IE
if (document.all) {
  element.style.setAttribute('cssText', 'propertyName: value !important');

  // Modern browser
} else {
  element.setAttribute('style', 'propertyName: value !important');
}

or (probably currently the preferred method)

From MDN

element.style.setProperty(propertyName, value, priority); where (optional) priority simply requires "important" to be passed.

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.