I created a simple jQuery plugin to change an element to blue, and can pass it a parameter to change the element to a given color.
I now wish to create a new plugin which changes the color to yellow without having to pass the color as a parameter. I've read https://stackoverflow.com/a/4414356/1032531, but it seems to describe adding a method to a object.
How is this best accomplished?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Extend jQuery Plugin</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js" type="text/javascript"></script>
        <script type="text/javascript"> 
            (function($){
                var defaults = {
                    'color'  : 'blue'
                };
                var methods = {
                    init : function (options) {
                        var settings = $.extend({}, defaults, options);
                        return this.each(function () {
                            $(this).css('color',settings.color);
                        });
                    },
                    destroy : function () {
                        return this.each(function () {});
                    }
                };
                $.fn.changeColor = function(method) {
                    if (methods[method]) {
                        return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
                    } else if (typeof method === 'object' || ! method) {
                        return methods.init.apply(this, arguments);
                    } else {
                        $.error('Method ' +  method + ' does not exist on jQuery.changeColor');
                    }    
                };
                }(jQuery)
            );
            jQuery.fn.extend({
                changeColorToYellow: function() {
                    //What do I do?
                    //$.changeColor({color:'yellow'})
                }
            });
            $(function() {
                $('#myElement1').changeColor();
                $('#myElement2').changeColor({color:'red'});
                $('#myElement3').changeColorToYellow();
            });
        </script>
    </head>
    <body>
        <p id='myElement1'>myElement1</p>
        <p id='myElement2'>myElement2</p>
        <p id='myElement3'>myElement3</p>
    </body>
</html>
 
     
    