Some of the examples of Events are as follows:
- Click or double click to an HTML element
- Mouse pointer over an HTML element
- Keyboard events by pressing keys
- Loading webpages
- Selection a radio button or check box
Consider an Example, to create a program where users has a button. If user press that button then a note appears saying “don’t click here again!” For this you must use the click event. When user clicks that button then click event fires the function of appearing the selected HTML element.
// jQuery script is just started with the ready event which is most important to run a jQuery script
//.click (); event which can be fired if someone clicks on its event specified HTML element
// This is the scripting area for this .click(); event
// double click event
// mouseleave event
// Scripting area
<!—Event specified HTML elements-->
<!—The selected HTML element where we get all the result of different functions according to the event’s actions -->
In the above script, I used some most famous and important events:
1) .ready(); event:
This event triggers when our webpage loads itself completely included image and videos. This event makes sure that everything is ready and OK, so now just start printing jQuery results. We can’t work in jQuery without this event. We can’t use this event with any tag, id or class. Because it works with the whole document.
2) .click(); event:
This event fires when user clicks on the click event specified HTML element below
Then this event triggers:
3) .dbl_click(); event:
This event works in the same way as .click(); event works. But it need double clicks to be fired. Otherwise its same.
4) .mouseenter(); event:
This event doesn’t need to be clicked its html element. It just needs a hover of mouse pointer at its specified HTML element to be fired or triggered. When you take your mouse over its specified HTML element then the script inside its function will be executed.
5) .mouseleave(); event:
This event works in the opposite way of .mouseenter(); event. When you take back your mouse pointer from this event’s specified HTML element then the script inside this event’s function will be executed.
I hope, by going through this tutorial you must have got an idea of using Events in jQuery. In case of any views or suggestions regarding this post you can let me know in comment section below. Till then happy learning.