Skip to content

Instantly share code, notes, and snippets.

@jazzyjackson
Last active November 25, 2015 10:01
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 jazzyjackson/485a3e771b6488f85f77 to your computer and use it in GitHub Desktop.
Save jazzyjackson/485a3e771b6488f85f77 to your computer and use it in GitHub Desktop.
<button id="myButton"> Hello World! </button>
<script>
var button = document.getElementById("myButton")
function speak(){ alert("hi!") } // this is a function declaration, allowing 'speak' to be used anywhere in the code, even above this line.
//you can also assign an "anonymous function" to a variable name, but this function can only be called below where it was assigned
//var speak = function() { alert("hi!") }
button.onclick = speak
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment