This sample code snippet shows how to work with events (eg. onclick and onmouseover). It also shows how to use those annoying alert messages…but please, only use them for good! You will also be introduced to HTML form elements such as buttons.

Make sure you also check out the video here which explains how to use some of the other event types.

<!DOCTYPE html>
<html lang="en"
 <meta charset="utf-8"/>
 <title>JavaScript - Events</title>
 <script type="text/javascript">
 // alert("Welcome to my web page"); would bring up an alert whenever the page loads
 // However, we will use a click event to load an alert message instead, and this will be in the body section of the html page
 <input type="button" value="click me" onclick="alert('You clicked me');"/>
 <input type="button" value="hover me" onmouseover="alert('You hovered over me');"/>