css - can't apply style to a button on it's click event -
i have created button dynamically in html5 + javascript. have assigned click event button. when clicked it, it's content & background color should change. content changing fine, bgcolor not changing.
my code is;
<style> .selectbtn{ height:60px;width:80px;background-color:yellow; } </style> <script> var container = document.getelementbyid('abc'); function dx(){ var btn = document.createelement('button'); btn.type = 'button'; btn.classname = 'selectbtn'; btn.innerhtml = 'submit'; container.appendchild(btn); btn.onclick = function() { this.innerhtml='voted'; this.style.backgroundcolor:'blue'; } dx(); </script> <body><div id='abc'></div></body>
use =
instead of colon
. use this:-
this.style.backgroundcolor = "#f47121";
Comments
Post a Comment