0

is it possible to add to an element type or maybe a css selection an own event function?

something like:

$("a").bind("blub", function() { alert("aaa" + this); });

$("a").get(0).blub();

i want define some functions which are only available for some special elements eg.:

the <div class="myDivContainer">...</div> should have the function available:

$("myDivContainer").get(0).blub();

but on maybe:

$("myDivSeparator").get(0).blub(); 

this should not work, because it was not defined for it

is this possible?!

1 Answers1

5

You can create custom events with bind and trigger. See for example this question.

You must use the trigger method to call the custom event:

$("a").bind("blub", function() {});
$("a").trigger("blub");

Of course you can trigger the "blub" event only for elements that bind has been called before.

If you want to use blub as a method, then you need to modify/extend the jQuery itself.

Community
  • 1
  • 1
kgiannakakis
  • 103,016
  • 27
  • 158
  • 194