2
In jQuery, I know it is possible to extend and create functions for certain types of operations through $.fn
.
Thus:
(function ( $ ) {
$.fn.clickOut = function (callback) {
var that = this;
$(document).click(function (e) {
if ( $(e.target).closest(that).size() > 0) {
return;
}
$.isFunction(callback) && $.proxy(callback, that)(e);
});
}
})( jQuery )
The function works correctly. But how can I make it work with the use of on
, because I need to assign it to dynamically created elements.
Is there any way to "create a function" (I don’t know how else to say this) for the on
of jQuery
?
Roughly speaking, I wanted it to work like this:
$('div').clickOut(); // Forma normal
// Forma que tentei, e não deu certo.
$('#my-uls').on('clickOut', 'li', function (...){});
Regarding the
on
we have this reference: http://answall.com/questions/5196/qual-a-diferen%C3%A7a-entre-o-onclick-Function-e-o-clickfunction– Wallace Maxters
So you tried?
$('#my-uls').on('clickOut', 'li', function (){ $(this).clickOut(); });
– Guilherme Lautert
I’ll try again. It hadn’t worked out
– Wallace Maxters