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:-
can clear style value?
can append value existing style attribute ?
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
Post a Comment