Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, so as promised, here's my 'best-way-I'd-do-this' solution, freely open to crit and comments. I'm also going to try and base this as closely as possible to your code so that you can see how the elements relate to each other.</p> <p>I have no idea which <code>img</code> your adding the click to, or what <code>#load</code> points to. The <code>.load()</code> function in jQuery also needs a URL to load, which seems to be missing.</p> <p>I'm going to assume, from your question, that you have a bunch of images on your page, and when you click on one of them their larger counterpart will be displayed in a <code>div</code> below them. Hope this is accurate. First, let's start with the HTML:</p> <pre><code>&lt;div class="small_images_container"&gt; &lt;img src="/images/640/001.jpg" /&gt; &lt;img src="/images/640/002.jpg" /&gt; &lt;img src="/images/640/003.jpg" /&gt; ... &lt;/div&gt; &lt;div id="big_image_container"&gt;&lt;/div&gt; </code></pre> <p>So we have some images, and we have a container to put the bigger one in, awesome. Now for the script, which needs to add the click events as well as fetch the bigger image and put it into the <code>.big_image_container</code>...I'm not worried about the <code>alt</code> tag in this solution, and rather I'm going to break up the original <code>src</code> attributes with Javascript's <code>.split()</code> function and grab the image's filename that way...here we go:</p> <pre><code>&lt;script type='text/javascript'&gt; $(document).ready(function(){ $('.small_images_container img').click(function(){ // get the image and its 'src' attribute... var image = $(this); var src = image.attr('src'); // split the 'src' attribute with the '/' character and get the // last element in the array... src = src.split('/'); var filename = src[src.length-1]; // now we can create the image we're going to put in the // large image container... var image_folder = '/images/1024/'; var large_image = $('&lt;img /&gt;'); large_image.attr('src', image_folder + filename); // set the HTML of the container to the new image... // first, clear out whatever HTML was in there, then add // the new image... $('#big_image_container').html(''); $('#big_image_container').append(large_image); }); }); &lt;/script&gt; </code></pre> <p>I hope this makes sense and helps! Please let me know if I've missed something, or if something is unclear!</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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