Note that there are some explanatory texts on larger screens.

plurals
  1. POSimplest way to attach a function to [onload, on a set of elements click, and on another set of elements click]?
    text
    copied!<p>I'm having a hard time finding the syntax or even just an elegant solution for this.</p> <p>I want to implement a "currently viewing" label for a carousel that is used to preview additional images. I inject the label into each slide from the server but set them with the class hidden. </p> <p>Here is my function:</p> <pre><code>var api = $('#imageNav').data('tabs'); var currentImageId = '#' + api.getCurrentPane().attr('id'); var $carousel = $('#carousel_slides'); $carousel.find('a &gt; span').addClass('hidden') .parentsUntil($carousel).find('a[href=\"' + currentImageId + '\"] &gt; span').removeClass('hidden'); </code></pre> <p>I'd like to be able to run that function on 3 different events:</p> <pre><code>1. DocumentReady() 2. $('#imageNav li &gt; a').click() 3. $('#carousel_slides span &gt; a').click() </code></pre> <p>Is there a way to combine all 3 with .on() or do I have to set it up for all 3 individually?</p> <p>Thanks.</p> <p><strong>EDIT</strong> - I tried this in my $(function () {}); but no luck.</p> <pre><code>var SetCurrentlyViewingLabel = function() { var api = $('#imageNav').data('tabs'); var currentImageId = '#' + api.getCurrentPane().attr('id'); var $carousel = $('#carousel_slides'); $carousel.find('a &gt; span').addClass('hidden') .parentsUntil($carousel).find('a[href=\"' + currentImageId + '\"] &gt; span') .removeClass('hidden'); }; SetCurrentlyViewingLabel(); $('#imageNav li &gt; a, #carousel_slides span &gt; a').click(SetCurrentlyViewingLabel()); </code></pre>
 

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