JQUERY OPTIONS FOR METHOD STOP WORKING

E E Cummings

Total Post:26

Points:182
Posted by  E E Cummings
JQuery 
 1243  View(s)
Ratings:
Rate this:
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

  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: jQuery options for method stop working

    Hello!

    In your 1st snippet code replace say with options.say

    (function($){

        jQuery.alertSay = function(options){

            var options = $.extend( options , {say:'open'}); // some error here

            alert('We are currently ' + options.say + '!');

        };

    })(jQuery);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!