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 Jain
  • 21,353
  • 33
  • 103
  • 168

1 Answers1

10

I think it will help you:

element.style.cssText += ';display:block !important;'
Alex
  • 11,115
  • 12
  • 51
  • 64