Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You use a closure to protect the global scope (which is good), but forget to provide external interfaces for the functionality.</p> <p>It's not entirely clear from your code, but I presume what you want is something like this:</p> <pre><code>// inside your browseImages function var imageObject = $(this); // somewhere near the bottom $.fn.browseImages = browseImages; // so that you can use it like </code></pre> <p>And what your're doing in <code>init()</code> function doesn't really belong to the plugin that you are making. You can move the whole init function directly to <code>$(document).ready(...)</code></p> <p><strong>UPDATE</strong></p> <p>Complete code for <code>main.js</code></p> <pre><code>(function($) { $.fn.browseImages = function(type) { var image = []; image[3] = "http://farm5.static.flickr.com/4006/5131022085_62876bbfbd_b.jpg"; image[2] = "http://farm6.static.flickr.com/5201/5289991939_46a20dd9fd_o.jpg"; image[1] = "http://farm3.static.flickr.com/2127/5807551517_72d39a1d19_b.jpg"; var imageObject = $(this); var selection; if (type == "left") { for (var i=1; i &lt; Things.length; i++) { if (imageObject.attr("src") == Things[i]) { selection = i; } } imageObject.attr("src",image[selection]); } else { for (var i=1; i &lt; Things.length; i++) { if (imageObject.attr("src") == Things[i]) { selection = i; } } imageObject.attr("src",image[selection]); }; } })(jQuery); $(function() { // &lt;-- equivalent to $(document).ready(...) $("h1").click(function() { $('#image').browseImages("left"); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload