0

So I want to make myself a Jquery plugin, you something dynamic I can use again and again over projects. I'm already locally serving the latest jquery library version(jquery-2.1.4.min.js) and then linking my plugin. like this..

<head>
other code resources and meta...

  <script type="text/javascript" src="/js/libs/jquery-2.1.4.min.js"></script>
  <script type="text/javascript" src="/js/functions.jquery.js"></script>
  <script type="text/javascript" src="/js/green.js"></script>
</head>

inside the '/js/green.js' i have the following code(Which I got off the web by the way).

(function ( $ ) {
     $.fn.greenify = function( options ) {

        // This is the easiest way to have default options.
        var settings = $.extend({
            // These are the defaults.
            color: "#556b2f",
            backgroundColor: "white"
        }, options );

        // Greenify the collection based on the settings variable.
        return this.css({
            color: settings.color,
            backgroundColor: settings.backgroundColor
        });

    };

}( jQuery ));

My HTML document contains the following code..

$( "div" ).greenify({
color: "orange"
});

I just don't understand why nothing is happening. To the color of all 'div' elements. Can anyone shed some light on what the bug might be?? Thanks in advance.

  • Does the selector find the elements you're targeting – `$("div").length > 0`? If not, the reason is likely as explained in "[Why does jQuery or a DOM method such as getElementById not find the element?](http://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element)" – Jonathan Lonowski Nov 08 '15 at 16:16
  • 1
    Otherwise, what you've posted here appears to be able to work fine, http://jsfiddle.net/pvnx3njz/. Are any errors occurring? Have you checked the console in your browser's developer tools? – Jonathan Lonowski Nov 08 '15 at 16:21

0 Answers0