Element addEventListener() Method - Change the background color of a <button> element: - Javascript DOM

Javascript examples for DOM:Element addEventListener

Description

Element addEventListener() Method - Change the background color of a <button> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button id="myBtn">Test</button>

<script>
document.getElementById("myBtn").addEventListener("click", function(){
    this.style.backgroundColor = "red";
});// w  ww  .j a  v a2 s . c  o  m
</script>

</body>
</html>

Related Tutorials