Created
February 9, 2019 23:33
-
-
Save ehzawad/94c12e12644855ac734f766a55052336 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> | |
<head> | |
<script> | |
document.addEventListener('DOMContentLoaded', function() { | |
// Have each button change the color of the heading | |
document.querySelectorAll('.color-change').forEach( (button) => { | |
button.onclick = () => document.querySelector('#hello').style.color = button.dataset.color | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<h1 id="hello">Hello!!</h1> | |
<button class="color-change" data-color="red">Red</button> | |
<button class="color-change" data-color="blue">Blue</button> | |
<button class="color-change" data-color="green">Green</button> | |
<button class="color-change" data-color="pink">Pink</button> | |
<button class="color-change" data-color="cyan">Cyan</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment