JavaScript Tutorial

Define JavaScript

JS Arithmetic Exercise

JavaScript Comment

JavaScript Variable

JavaScript Operators

Conditional Statements

Logical Operators

JavaScript Slider

JS Login Form

JS Popup Boxes

JavaScript Loops

JavaScript Arrays

JS Mouse Events

JS Keyboard Events

Styling Elements

External JavaScript

JS Noscript Tag

JS String Functions

JS Math Functions

JS Random

JS Date Functions


JS Assignment

JS Question-Answer

Page Stats

Visitor: 440

JavaScript Events

JavaScript interaction with HTML is handled through events. Event occur's when the user or the browser manipulates a page. For example: When the page loads, clicking a mouse button, pressing any key, closing a window, resizing a window, etc. all are the examples of events. Events are the part of Document Object Model(DOM).

JavaScript Mouse Events

Example 1: JavaScript onclick event.

<h1 onclick="'red'">Click Me!</h1>

Example 2: JavaScript onmouseover, onmouseout event.

function bgChange(bg) {;

<td onmouseover="bgChange('red')" onmouseout="bgChange('transparent')" bgcolor="red"> </td>       

Example 3: JavaScript onmouseover, onmouseout event.

function nameon() {
function nameout() {
document.getElementById('h2text').innerHTML="How are you today?";

Example 4: JavaScript onmousedown, onmouseup event.

<img src="images/cheetah.jpg" onmouseup="this.src='images/cheetah.jpg'" onmousedown="this.src='images/tiger.jpg'">

Example 5: JavaScript onmouseenter, onmouseleave event.

<marquee direction="left" bgColor="green" onmouseenter="this.stop()" onmouseleave="this.start()">
Scrolling Text with JavaScript events onmouseenter and onmouseleave

Example 6: JavaScript onmousemove event.

var i=1;
function moveright() {