I ve created a jQuery function called "onEnter". It works great on the run, but I need to trigger the event whenever I want. Somethink like this:
$(obj).onEnter(function(){ doSomething(); });
That works like a charm. Then I want to trigger:
$(obj).onEnter();
But this doesn t seems to work. Here s is my code. Thanks in advance.
$.fn.extend({
onEnter: function(fn) {
this.each(function() {
new $.onEnter( this, fn );
});
return this;
}
});
$.onEnter = function( obj, fn ) {
if(typeof fn == function )
{
$(obj).keypress(function(e){
if(e.which == 13)
{
e.preventDefault();
fn(obj);
}
});
};
return;
};