3

I want to write an inline style viz block !important using javascript code. Code looks like this

element.style.display = 'block !important'; // This does not work (Approach 1)

However,

element.style = 'display:block !important'; // works perfectly (Approach 2)

But Approach 2 is not acceptable for the obvious reason it will over-ride earlier inline styles. You can see this in this DEMO at Jsbin

Q1: How can I set display: block !important property using javascript and it has to be inline.

Q2: I want to know why Approach1 does not work ?

Sachin
  • 20,754
  • 28
  • 93
  • 162

1 Answers1

8

I think it will help you:

element.style.cssText += ';display:block !important;'
Pinal
  • 10,775
  • 12
  • 49
  • 62