UX Design and Development course

Bind function to event

Playing with functions - a mini program that can be re-used

First we need to declare a 'function' and give it a name

The () are what hold the parameters of the function.

var myFunction = function() {
  // This is called the 'Decloration'
  alert('Oh snap! A freaking box bro!'); // Simple alert box with text

myFunction(); is called automatically into action

Then we need to add this to the HTML:

<button onClick='myFunction()'>I am a button, I do magic</button>

Play with code

JS Bin