The onclick Event Handler

Published on: October 15, 2016

Welcome to the seventeenth Easy JavaScript Tutorial, Beginner JavaScript Tutorial, part of Easy Programming! In this tutorial, we start using buttons! Why? Because we're going to look at the onclick event handler. This will allow us to do many more complex actions with JavaScript because we can now take click-input from users. 

There is also an onclick event listener, this is something that we will cover in a later tutorial. If you know how an event handler works, an event listener will be extremely easy. 

Syntax of the onclick event handler

document.getElementById("id_name").onclick = function(){
	//do stuff with the code after element with #id_name was clicked

To fork the fiddle and follow along:

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!