JavaScript Events

The web is a dynamic environment where a lot of things happen. Most appropriately, they’re called events. Some of these events, like a user clicking a button or moving the mouse over a link, are of great interest to a JavaScript coder.

events

  1. onClick event: triggered by you as you click the link;
  2. onUnload event: triggered by the web browser as it leaves the current web page;
  3. onLoad event: triggered by the browser as the new web page content is loaded.

Example specified below

<a href="http://html.net" onclick="alert('Going anywhere? Not so fast!'); return false;">Click Me!</a>

JavaScript basics

  <!DOCTYPE html>
	  <html>
	  <head>
	  <title>My first JavaScript page</title>
/*Load in separate file */
<script type="text/javascript" src="yourjavascript.js"></script>
	  </head>
	  <body>
        
	  <script type="text/javascript">
	  //JavaScript code goes here
	  alert('Hello World!');
      </script>
		
	  </body>
	  </html>

Is JavaScript the same as Java?

No, they are not.

Java (developed by Sun Microsystems) is a powerful and much more complex programming language in the same category as C and C++.

JavaScript is a scripting language, that is, a lightweight programming language that is interpreted by the browser engine when the web page is loaded.