Could anyone tell me why changing colour after performing onclick doesn't work here ?
function butt(color) {
if(document.getElementById("bt").style.backgroundColor=="green"){
document.getElementById("bt").style.backgroundColor="purple";
}
};
document.getElementById("bt").addEventListener("click", function() {
butt("green")
});
#bt {
background-color:yellow;
border-radius:10%;
padding:10px;
margin:20px;
}
<div class="row">
<div id="forbutton">
<button type="button" id="bt">It's me MrButton !</button>
</div>
</div>
yellow == green? make any sense?style.backgroundColorfrom the inline style so it would ignore anything you add to your css file as it is not inline (you need to use something likeelement.getComputedStyle) - and as Sagar says you have used yellow but compared against green. One final thing would be why are you passing a variable into the function but not using it?window.getComputedStyle(element).backgroundColour- but it will return an rgb colour rather thanredorblue