JQuery Custom Events

As I have stated before, JQuery is an extremely powerful tool. One of the most under-discovered (but extremely useful) features of JQuery is extend-able event binding. There are several events that are backed into the JQuery framework, but you can create, bind, and trigger your own JQuery events very easily.

Custom Event Trigger
The code below is all it takes to trigger your own custom event. You can bind to this custom event and raise it whenever you want to execute the code inside of the bind.


$.event.trigger("myEventName");

Custom Event Binding
The code below creates a bind to the custom event and will be executed whenever the custom event is triggered.


$(this).bind("myEventName",function(){
alert("myEventName triggered");
});

That’s all there is to it! JQuery custom events are extremely useful. How do you plan to use custom events in your code?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>