Take the 2-minute tour ×

I'm attempting to build a way for my selectors to 'listen' to 'global' events that are beyond the typical 'click' 'change' 'submit' etc. I've explored the various 'eventmanagers' that I could find, and they're all still designed for forms. Is there any way to do something like this for non-standard (i.e. custom) events? The goal is to have selectors subscribe to an event, and then be able to trigger it in one place and it will raise it for everything subscribed to it.

Inserting example for demonstration.

 return this.each(function () {
  $(this).live('ON_CONTENT_CHANGING', function (e) {
    overlayCSS: { opacity: 1, color: '#000' },
    timeout: 800


  $(this).live('ON_CONTENT_CHANGED', function (e) {


// rest of plugin...

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

This is built into jQuery, for example:

$(".button").bind("myEvent", function() {
  alert("myEvent fired on " + this.id);

Trigger by:


Or on a specific element (or any selector, like everything else jQuery):


This uses .bind() and .trigger(). As Jacob points out in comments, you can also bind with .live() to custom events in 1.4+, like this:

$(".button").live("myEvent", function() {
  alert("myEvent fired on " + this.id);
share|improve this answer
In addition, if you use "live()" instead of "bind()" you can bind to a selector and new elements that match the selector will be subscribed for that event, even if they didn't exist when you set up the binding. –  JacobM Apr 1 '10 at 16:48
@JacobM:: However, keep in mind that live prior to 1.4 was limited to click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup. Source: api.jquery.com/live –  Powerlord Apr 1 '10 at 16:50
I have read somewhere that the "*" selector is pretty bad to use, is there any truth to that? Won't this propogate to every item in the DOM? –  Ciel Apr 1 '10 at 16:52
Hrnm. This doesn't seem to work with live() even on jquery 1.4 for me. –  Ciel Apr 1 '10 at 16:56
@Stacey - Have a link to the non-working example? And yes, "*" goes to every DOM object, you can restrict it down to things you know are bound, classes, inputs, whatever that may be. –  Nick Craver Apr 1 '10 at 16:58
show 5 more comments

Your Answer


