How it works?
The $.on()
function is super useful 👌 when you're dealing with events. When you want to execute a command when you click on a button, when you hover an element, etc...
Here are the most used JavaScript events, which you'll be able to use with the $.on()
function.
Events | Description |
---|---|
change | An HTML element has been changed |
click | The user clicks an HTML element |
mouseover | The user moves the mouse over an HTML element |
mouseout | The user moves the mouse away from an HTML element |
keydown | The user pushes a keyboard key |
load | The browser has finished loading the page |
Here is a complete documentation of every event that you can use with the $.on()
function 😊.
How to use it?
The $.on()
function needs 3 arguments, which are:
- the element
- the event
- and the callback function
These 3 arguments are required to make this function work.
Let's have a look at an example. Here, we'll display an alert when a user clicks on a button:
HTML:
<button>Do not click on me!</button>
JS:
$.on($.select("button"), "click", function () {
alert("🚨 You clicked on me!");
}
⚠️ Questions?
Don't hesitate to ask your questions ⁉️ in the issue part 😁