forum

Home / DeveloperSection / Forums / jQuery options for method stop working

jQuery options for method stop working

E E Cummings 2144 20-Jul-2013
Hell developers!

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


Updated on 20-Jul-2013

Can you answer this question?


Answer

1 Answers

Liked By