snipt

Ctrl+h for KB shortcuts

JavaScript

Jquery Submenu - active - remove and add

1
2
3
4
$("#submenu01").on("click", "a:not(.active)", function ( event ) {
    $(".active", event.delegateTarget).removeClass("active");
    $(this).addClass("active");
});
https://snipt.net/embed/af6aade45f123b2636cd4b7b8558e28f/
/raw/af6aade45f123b2636cd4b7b8558e28f/
af6aade45f123b2636cd4b7b8558e28f
js
JavaScript
5
2019-06-15T05:45:19
True
False
False
Aug 05, 2013 at 12:29 PM
/api/public/snipt/72025/
jquery-submenu-active-remove-and-add
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#submenu01&quot;</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;click&quot;</span><span class="p">,</span> <span class="s2">&quot;a:not(.active)&quot;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span> <span class="nx">event</span> <span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;.active&quot;</span><span class="p">,</span> <span class="nx">event</span><span class="p">.</span><span class="nx">delegateTarget</span><span class="p">).</span><span class="nx">removeClass</span><span class="p">(</span><span class="s2">&quot;active&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">addClass</span><span class="p">(</span><span class="s2">&quot;active&quot;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
active, add, addClass, class, jquery, remove