Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is wrong with my external jQuery File?
    text
    copied!<p>I am building a image slideshow. Currently, I have attached the event to a H1 element. Here is my code stored in a file <code>main.js</code> in a folder <code>jq</code>:-</p> <h2><em>UPDATED CODE:</em></h2> <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; image.length; i++) { if (imageObject.attr("src") == image[i]) { selection = i + 1; } } imageObject.attr("src",image[selection]); } else { for (var i=1; i &lt; image.length; i++) { if (imageObject.attr("src") == image[i]) { selection = i + 1; } } imageObject.attr("src",image[selection]); }; } })(jQuery); $(function() { // &lt;-- equivalent to $(document).ready(...) $("h1").click(function() { $('#image').browseImages("left"); }); }); </code></pre> <h2><em>UPDATED CODE:</em></h2> <p>(THE INIT HAs BEEN cOMMENTEd HERE) Here is my jQuery in the header tag of HTML:-</p> <pre><code>&lt;!-- Scripts --&gt; &lt;script src="http://rhnvrm.co.cc/jquery.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script src="jq/main.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;!--Initialize jQuery &lt;script type="text/javascript"&gt; $(document).ready( function() { init() }); &lt;/script&gt; --&gt; </code></pre> <p>And here is the Image in the body tag whose <code>src attr</code> I am editing:-</p> <pre><code>&lt;div id="imageholder"&gt; &lt;img id="image" src='http://farm3.static.flickr.com/2127/5807551517_72d39a1d19_b.jpg' width="900px" height="500px"/&gt; &lt;/div&gt; </code></pre> <hr> <p>NOTE: I am a person who you can categorize as a NOOB in jQuery</p>
 

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