javascript - How to dynamically change CSS style attribute of DIV tag? -


we have div tag: <div id='div1' style="background-color:red"></div>

i know how can change style attribute of div tag:-

  1. can clear style value?

  2. can append value existing style attribute ?

  3. can set new value style attribute

thanks in advance.

var div = document.getelementbyid('div1');  // clear value div.setattribute('style','');   // or div.removeattribute('style');  // set style / append style div.style.backgroundcolor = '#ff0000'; 

don't modify style attribute directly when adding or changing styles unless want remove them all.

javascript removeattribute: https://developer.mozilla.org/en-us/docs/web/api/element.removeattribute javascript style: https://developer.mozilla.org/en-us/docs/web/api/htmlelement.style


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -