Work with onClick and onLoad events JavaScript


show more Learn how to write JavaScript code to respond to the two most common events: loading content and clicking. Find out how to use onClick to react to user clicks and use onLoad to respond to page refreshes and other load events. show less
please wait ...

Working with onClick and onLoad events

So now I'm going to write some code to respond to common events, and if there are two events in any programming language that are the most common, it's clicking on something and loading something. So I have a regular HTML page here with some images and CSS linking to a JavaScript file that's actually currently empty, and I have both of those just open in my editor here. So the simplest way that I could cause something to happen is like I have on Line 28 here where I just have the onclick = inline code in my HTML itself, and no particular surprise on what this is going to do. If I click that button, I'll run that alert message.

But we are not going to do any more code like this. We are going to do it properly. So I am going to jump across into my script.js, which is already being linked to, but there's no script in it yet. Now it's easy to think that we need a button or a link to click on. We can support the idea of clicking on anything in our document. Click is a ver...

Working with onClick and onLoad events
Video duration: 7m 36s 5h 31m Beginner

Viewers:

Learn how to write JavaScript code to respond to the two most common events: loading content and clicking. Find out how to use onClick to react to user clicks and use onLoad to respond to page refreshes and other load events.

Subjects:
Developer Web
Software:
JavaScript
Author:
please wait ...