Note that there are some explanatory texts on larger screens.

plurals
  1. POUse jquery to target classes that are added dynamically?
    primarykey
    data
    text
    <p>I have a slider (flexslider) that dynamically adds the class "flex-active-slide" to the active <code>&lt;li&gt;</code>. </p> <p>I want to use jQuery to do something when a specific slide has the class "flex-active-slide." I tried the following, but it doesn't work because the .flex-active-class is added on the fly after this has already run:</p> <pre><code>if ( $('#slider li.about').is('.flex-active-slide') ){ $('.nav li.about').show(); } </code></pre> <p>In my research, it seems I want to use on(), but all the examples I see relate it to an event like click() or hover(). This isn't triggered by anything like that -- the class just "appears." I can't figure out how to format it. Something like this...?</p> <pre><code>$(document).on('???',".flex-active-slide", function() { $(".nav li.about").show();; }) </code></pre> <p>I'm sure that is embarrassingly incorrect... I appreciate any help you can give!!</p> <p>Note: I can't simply use CSS because the .nav I'm trying to affect is completely unrelated to the slider div.</p> <p>UPDATE: Here is what appears to be the code in the flexslider.js that controls adding the flex-active-slide class. Is there anything here that suggests anything I could do?</p> <pre><code> slider.flexAnimate = function(target, pause, override, withSync, fromNav) { if (asNav &amp;&amp; slider.pagingCount === 1) slider.direction = (slider.currentItem &lt; target) ? "next" : "prev"; if (!slider.animating &amp;&amp; (slider.canAdvance(target, fromNav) || override) &amp;&amp; slider.is(":visible")) { if (asNav &amp;&amp; withSync) { var master = $(vars.asNavFor).data('flexslider'); slider.atEnd = target === 0 || target === slider.count - 1; master.flexAnimate(target, true, false, true, fromNav); slider.direction = (slider.currentItem &lt; target) ? "next" : "prev"; master.direction = slider.direction; if (Math.ceil((target + 1)/slider.visible) - 1 !== slider.currentSlide &amp;&amp; target !== 0) { slider.currentItem = target; slider.slides.removeClass(namespace + "active-slide").eq(target).addClass(namespace + "active-slide"); target = Math.floor(target/slider.visible); } else { slider.currentItem = target; slider.slides.removeClass(namespace + "active-slide").eq(target).addClass(namespace + "active-slide"); return false; } } ... </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.
 

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