javascript - How to call object function after click -
i know how make code work: http://jsfiddle.net/lbxvd/2/. it's clean jqueryboilerplate, i'm interested in part of code:
plugin.prototype = { init: function() { /// create element <a> click function myel = $('<a/>', { href: '#', text: '###', click: function(e){this._handler();} }); $('ul').before(myel); }, //handler click events on <a> element... _handler: function(el, options) { alert("my handler called"); } };
how can call function _handler after click on created element?
thanks!
your jsfiddle isn't helpful since doesn't show result ... think it's because this
in this._handler()
call not think (it <a>
element , not prototype object).
try
init: function() { var self = this; // **** /// create element <a> click function myel = $('<a/>', { href: '#', text: '###', click: function(e){self._handler();} // **** });
Comments
Post a Comment