Java Script Snippet,School,Senza categoria
This example uses the addEventListener() method to add many events on the same button.
<button id="myBtn"> Try it </button>
<script>
var x = document.getElementById("myBtn");
x.addEventListener("mouseover", myFunction);
x.addEventListener("click", mySecondFunction);
x.addEventListener("mouseout", myThirdFunction);
function myFunction() {
document.getElementById("demo").innerHTML = "Moused over!
"
}
function mySecondFunction() {
document.getElementById("demo").innerHTML = "Clicked!
"
}
function myThirdFunction() {
document.getElementById("demo").innerHTML = "Moused out!
"
}
</script>
Guarda il codice su CodePen