I have created a plugin which will create dynamic element and attach to some container . I want to bind events for that element inside my plugin so that it can use plugin information etc.
(function ($, window, document, undefined) {
$.scrollTo = function(el, options){
// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
base.init = function(){
base.options = $.extend({},$.scrollTo.defaultOptions, options);
// Put your initialization code here
};
// On click
base.$el.click(function (event) {
event.preventDefault();
var span = $('<span class="myElement"></span>');
span.appendTo('#main');
});
// Run initializer
base.init();
};
$.scrollTo.defaultOptions = {};
$.fn.scrollTo = function(options){
return this.each(function(){
(new $.scrollTo(this, options));
});
};
})(jQuery, window, document);
//Initialize plugin
$('.content #test').scrollTo();
I am creating a new element on click event and want to attach a click function to it and inside that function I want to utilize plugin options. How could I achieve that need help ?