Note that there are some explanatory texts on larger screens.

plurals
  1. POModify class with jQuery
    text
    copied!<pre><code>&lt;span class="here one-two-del-del other1"&gt;test&lt;/span&gt; &lt;span class="here one-two-aaa o2ther"&gt;test&lt;/span&gt; &lt;span class="here one-two-dsf other3"&gt;test&lt;/span&gt; &lt;span class="here one-two-213 o4ther"&gt;test&lt;/span&gt; &lt;span class="here one-two-sdf other5"&gt;test&lt;/span&gt; &lt;span class="here one-two-sdff o6ther"&gt;test&lt;/span&gt; &lt;span class="set one-two-aaaa"&gt;set 1&lt;/span&gt; &lt;br /&gt; &lt;span class="set one-two-bb-fff"&gt;set 2&lt;/span&gt; &lt;br /&gt; &lt;span class="set one-two-vcvc"&gt;set 3&lt;/span&gt; &lt;br /&gt; &lt;span class="set one-two-fgdfg-dfgfd-fgf"&gt;set 4&lt;/span&gt; &lt;br /&gt;​ ​$('.set').click(function(){ $('#here').??? })​ </code></pre> <p>i would like - if i click on .set then this should get own class and replace in all .here.</p> <p>For example if i click on <em>set 2</em> then all span with class .here should be:</p> <pre><code>​&lt;span class="here one-two-bb-fff other1"&gt;test&lt;/span&gt; &lt;span class="here one-two-bb-fff o2ther"&gt;test&lt;/span&gt; &lt;span class="here one-two-bb-fff other3"&gt;test&lt;/span&gt; &lt;span class="here one-two-bb-fff o4ther"&gt;test&lt;/span&gt; &lt;span class="here one-two-bb-fff other5"&gt;test&lt;/span&gt; &lt;span class="here one-two-bb-fff o6ther"&gt;test&lt;/span&gt; </code></pre> <p>i cant use removeClass because i dont know how is the current class. If i use .attr('class', 'new') then this replace all class, but i must still have class other1, o2ther etc</p> <p><a href="http://jsfiddle.net/NNhDd/" rel="nofollow">http://jsfiddle.net/NNhDd/</a></p> <p>Maybe i must use regular expression?</p>
 

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