Element addEventListener() Method - Add two click events on the same <button> element: - Javascript DOM

Javascript examples for DOM:Element addEventListener

Description

Element addEventListener() Method - Add two click events on the same <button> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
var x = document.getElementById("myBtn");
x.addEventListener("click", myFunction);
x.addEventListener("click", someOtherFunction);

function myFunction() {//from w w  w . jav  a  2s  .  co  m
    console.log("Hello World!")
}

function someOtherFunction() {
    console.log("This function was also executed!")
}
</script>

</body>
</html>

Related Tutorials