Created
January 29, 2020 21:28
-
-
Save Theo-denBlanken/6517f72faa8d4d0ca3d8473614579fc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>this bij enkele knoppen</title> | |
</head> | |
<body> | |
<h1>Klik op elk van deze knoppen en kijk in de console</h1> | |
<button>knop EEN</button> <br> | |
<button>knop TWEE</button> <br> | |
<button>knop DRIE</button> <br> | |
<button>knop VIER</button> | |
<script> | |
const alleKnoppen = document.getElementsByTagName('button'); | |
verwerkKnopKlik = function(e) { | |
// e.preventDefault(); | |
console.log(this.innerHTML); | |
this.style.backgroundColor = 'red'; | |
} | |
for(let i=0; i<alleKnoppen.length; i++) { | |
alleKnoppen[i].addEventListener('click', verwerkKnopKlik); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code voorbeeld van de werking van het keyword this bij events, die een functie aanroepen.