jQuery, bind custom functions to DOM elements

Viewed 29112

I have two divs in my app and I want them to have custom functions with the same signature, but with different actions, so that I could store the "current" div in a variable, and just call something like:

myCurrentDiv.theFunction(someEventData);
and have the corresponding methods fired up.

How can I do that using jQuery?

I tried doing something like:

$("#myFirstDiv").theFunction = function() {
    alert("theFunction on firstDiv");
}
$("#mySecondDiv").theFunction = function() {
    alert("theFunction on secondDiv");
}

6 Answers
Related