Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Jhonatas Kleinkauff said: you have your <code>status</code> and icons mixed in your initial code. On the first click, the status would be <code>mute</code>, so you would try to remove the class <code>ui-icon-volume-off</code>, which is not there, so in fact, no class gets removed. Afterwards you are adding <code>ui-icon-volume-on</code> and end up having both classes set at the same time, so both icons are shown.</p> <p>You are doing it right in your fiddle though (status is <code>unmute</code>, so sound is on and the class should be <code>ui-icon-volume-on</code>, which it is).</p> <p>To fix the code in your question, you would have to either switch the initial status to <code>unmute</code> as you did in the fiddle:</p> <pre><code>&lt;a class="button" title="Sound Mute/Unmute" data-status="unmute" onClick="$(this).SoundToggle();" id="soundstatus"&gt; &lt;span class="ui-icon ui-icon-volume-on"&gt;&lt;/span&gt; &lt;/a&gt; </code></pre> <p>or set the other HTML class:</p> <pre><code>&lt;a class="button" title="Sound Mute/Unmute" data-status="mute" onClick="$(this).SoundToggle();" id="soundstatus"&gt; &lt;span class="ui-icon ui-icon-volume-off"&gt;&lt;/span&gt; &lt;/a&gt; </code></pre> <p>You might want to look into jQuery <a href="http://api.jquery.com/toggleClass/" rel="nofollow"><code>.toggleClass</code></a> function which has a nice second parameter, a boolean switch to indicate if you want to add or remove the class. You could then do something like this:</p> <pre><code>var $soundIcon = $('#soundstatus span'); var soundShouldBeTurnedOn = currentStatus === "mute"; $soundIcon.toggleClass("ui-icon-volume-on", soundShouldBeTurnedOn) .toggleClass("ui-icon-volume-off", !soundShouldBeTurnedOn); </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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