I'm not sure if the question were asked already but I've live example so I hope my question may be useful. Here I've custom plugin for jQuery:
(function($){
jQuery.alertSay = function(options){
var options = $.extend({say:'open'}, options};
alert('We are currently ' + say + '!');
};
})(jQuery);
connected to the main index.html:
$(document).ready(function() {
$.alertSay({
say: 'on vacations'
});
});
And it doesn't work because of options, cause if I use simple method without any options, like this:
(function($){
jQuery.alertSay = function(){
alert('We are currently on vacations!');
};
})(jQuery);
It works just fine with the link like:
$(document).ready(function() {
$.alertSay();
});
Due to my poor knowledge in jQuery I'm unable to detect where my mistake is and it would be so nice from you to help me if possible. Thank you!
UPD: Thank you for your replies but unfortunately replacing
alert('We are currently ' + say + '!');
with
alert('We are currently ' + options.say + '!');
change nothing, no alert at all. But I've some errors:
Uncaught SyntaxError: Unexpected token } hallo.js:3
Uncaught TypeError: Object function (a,b){return new p.fn.init(a,b,c)} has no method 'alertSay' (in the html on string $.alertSay({)
thanks in advance
shreesh chandra shukla
20-Jul-2013In your 1st snippet code replace say with options.say