Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery "each" method
    text
    copied!<p>I'm a javascript beginner, and I'm having some trouble using jQuery's "each" method. I have a gallery module on a Joomla site that functions as a simple image slider. I added some code to allow a lightbox on the linked images. What I would like to do now is copy the thumbnail caption (that the module currently adds) to the Title attribute in the link so it shows up in the lightbox for each image. </p> <p>Here's how the HTML is structured...</p> <pre><code>&lt;div class="camera_wrap" id="camera_wrap_106"&gt; &lt;div class="cameraContents"&gt; &lt;div class="cameraContent"&gt; &lt;a class="camera_link" href="lightbox-large.jpg" title="This is where i need the caption"&gt;&lt;/a&gt; &lt;div class="camera_caption"&gt; &lt;div&gt;This is the caption&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="cameraContent"&gt; &lt;a class="camera_link" href="lightbox-large.jpg" title="This is where i need the caption"&gt;&lt;/a&gt; &lt;div class="camera_caption"&gt; &lt;div&gt;This is the caption&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="cameraContent"&gt; &lt;a class="camera_link" href="lightbox-large.jpg" title="This is where i need the caption"&gt;&lt;/a&gt; &lt;div class="camera_caption"&gt; &lt;div&gt;This is the caption&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <p>I've gotten the code this far, but it only copies the first caption div to each title attribute rather than executing it on each instance. Not sure if this is even the best start...</p> <pre><code>$("#camera_wrap_106 .cameraContent").each(function() { $("#camera_wrap_106 a.camera_link").attr('title', $("#camera_wrap_106 .camera_caption div").html()); }); </code></pre> <p>Thanks in advance!</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