JavaScript Events

Events are the users’ actions, a web page can respond to, such as,

  • Loading a page,
  • Mouse click,
  • Keystroke,
  • Click on submit button,
  • Pressing a key,
  • Closing a window, etc.

In this lesson, we will learn how to work with JavaScript events.

JavaScript onclick event

This event fires when a user clicks the mouse. On the click of the left mouse button, an HTML element gets clicked i.e., a function gets called. The onclick attribute is used for this.

Let us see an example to implement the onclick event in JavaScript:

Output

JavaScript onclick event

Click the Click Me!!! Button to fire an event:

JavaScript onclick event output

JavaScript ondblclick event

This event fires when a user double-clicks the mouse. On the double-click of the left mouse button, an HTML element gets clicked twice. The ondblclick attribute is used for this.

Let us see an example. We have considered the same example discussed above. The attribute ondblclick is set for the double click event:

Output

JavaScript ondblclick event

Click the Double Click Me!!! Button twice to fire an event:

JavaScript ondblclick event output

JavaScript onmouseover event

This event fires when the mouse pointer is kept over an HTML element. The onmouseover attribute is used for this. Let us see an example. We have considered the same example discussed above:

Output

JavaScript onmouseover event

Keep the mouse cursor on the button Keep the cursor here to fire an event:

JavaScript onmouseover event output

JavaScript Operators
JavaScript Objects
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading