Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created February 9, 2019 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehzawad/94c12e12644855ac734f766a55052336 to your computer and use it in GitHub Desktop.
Save ehzawad/94c12e12644855ac734f766a55052336 to your computer and use it in GitHub Desktop.
<!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