Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery on click activate another on click, but the closest one in the mark up
    primarykey
    data
    text
    <p>This is baking my noodle, any pro ideas/advice would great thanks.</p> <p>I have my mark-up below...</p> <pre><code>&lt;a href="#" class="launch-fancybox"&gt;Preview Image Gallery&lt;/a&gt; &lt;!-- lots of mark up in between --&gt; &lt;a href="enlarge-1.jpg" class="fancybox"&gt;&lt;img src="thumb-1.jpg" alt=""/&gt;&lt;/a&gt; &lt;a href="enlarge-2.jpg" class="fancybox"&gt;&lt;img src="thumb-2.jpg" alt=""/&gt;&lt;/a&gt; &lt;a href="enlarge-3.jpg" class="fancybox"&gt;&lt;img src="thumb-3.jpg" alt=""/&gt;&lt;/a&gt; &lt;a href="enlarge-4.jpg" class="fancybox"&gt;&lt;img src="thumb-4.jpg" alt=""/&gt;&lt;/a&gt; </code></pre> <p>Then my fancybox jquery...</p> <pre><code>$('.fancybox').on('click', function () { var data = $(this).attr('data-rel'); $('.fancybox[data-rel="' + data + '"]').attr('rel','fancybox-thumb').fancybox({ prevEffect : 'none', nextEffect : 'none', helpers : { title : null, overlay : { opacity : 0.8, css : { 'background-color' : '#000' } }, thumbs : { width : 50, height : 50 } }, closeClick: true }); }); </code></pre> <p>Now my question is, how can I get my link with the class 'launch-fancybox' to find the very first/closest link with the class 'fancybox' and run the script above.</p> <p>Basically I want simulate clicking on the first thumbnail. But instead by clicking the 'launch-fancybox' link.</p> <p>Any ideas or pointers in how I could do this would be awesome.</p> <p>Thanks</p> <p>======================================================</p> <p>I even tried putting my jquery into a function...</p> <pre><code>fancybox = function () { var data = $(this).attr('data-rel'); $('.fancybox[data-rel="' + data + '"]').attr('rel','fancybox-thumb').fancybox({ prevEffect : 'none', nextEffect : 'none', helpers : { title : null, overlay : { opacity : 0.8, css : { 'background-color' : '#000' } }, thumbs : { width : 50, height : 50 } }, closeClick: true }); }; $('.fancybox').on('click', fancybox); $('.launch-fancybox').on('click', function (e){ e.preventDefault(); $(this).closest('.fancybox').click(); }); </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