Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery : How to remove class for all element on click?
    text
    copied!<p>I would like to know if some one can improve my code... Using jQuery I'm trying to apply a class on the element we just click and disable this class on the other elements.</p> <p>You will se in my code that I'm trying to apply a class on the I just clicked and remove all the class on the others elements.</p> <p>But for the moment, I'm doing it the "easy and mega long way" as you can see in <em>$("choice1-1").click(function()</em> </p> <p>Can some help me with a code that could detect all the others ID ?</p> <p><strong>Here my code for the moment</strong></p> <pre><code>$(document).ready(function() { $('#stick-question-1').mouseenter(function() { $('#stick-choices-1').show(); }); $('#stick-choices-1').mouseleave(function() { $('#stick-question-1').show(); $('#stick-choices-1').hide(); }); $("choice1-1").click(function() { $(this).addClass('hover-etat'); $("#choice1-2").removeClass('hover-etat'); $("#choice1-3").removeClass('hover-etat'); $("#choice1-4").removeClass('hover-etat'); }); }); </code></pre> <p>And my HTML is like this</p> <pre><code> &lt;div id="stick-choices-1" class="stick-choices"&gt; &lt;a href="#" onclick="displayChoice1('Under 3\'9'); return false;" id="choice1-1"&gt;Under 3'9&lt;/a&gt; &lt;a href="#" onclick="displayChoice1('4\' to 5\'2'); return false;" id="choice1-2"&gt;4' to 5'2&lt;/a&gt; &lt;a href="#" onclick="displayChoice1('5\'3 to 5\'7'); return false;" id="choice1-3"&gt;5'3 to 5'7&lt;/a&gt; &lt;a href="#" onclick="displayChoice1('5\'8 and more'); return false;" id="choice1-4"&gt;5'8 and more&lt;/a&gt; &lt;/div&gt; </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