Working with Events
There are three main methods for working with events:
add a handler here I'm using the simplest method signature
trigger an event from a script
remove an event handler
Let's look at the .on() method:
// attach a handler
$("p").on("click", function() {
// do something
alert("Click!");
});Run the code above in the sandbox, and try clicking on a paragraph.
You can trigger this handler programmatically:
When you've had enough fun, you can remove the handler using the .off() method:
Although I wanted to mention one important thing — inside the handler you can access the DOM element using the this keyword. If you need to use jQuery tools, use the $(this) construct:
Last updated