Skip to content

Instantly share code, notes, and snippets.

@Theo-denBlanken
Created January 29, 2020 21:28
Show Gist options
  • Save Theo-denBlanken/6517f72faa8d4d0ca3d8473614579fc9 to your computer and use it in GitHub Desktop.
Save Theo-denBlanken/6517f72faa8d4d0ca3d8473614579fc9 to your computer and use it in GitHub Desktop.
<!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>
@Theo-denBlanken
Copy link
Author

Code voorbeeld van de werking van het keyword this bij events, die een functie aanroepen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment