Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery class checking and changing
    primarykey
    data
    text
    <p>I posted a question up yesterday that asked for some help on an image switching script I had written, thank you to all that helped me. I've extended the script and have run into a problem that I can't for the life of me spot where the problem is.</p> <p>HTML:</p> <pre><code>&lt;div id="feature-image"&gt; &lt;h1&gt;&lt;span&gt;A random heading&lt;/span&gt;&lt;/h1&gt; &lt;/div&gt; &lt;div id="feature-links"&gt; &lt;a class="a1" href="#"&gt;1&lt;/a&gt; &lt;a class="a2" href="#"&gt;2&lt;/a&gt; &lt;a class="a3" href="#"&gt;3&lt;/a&gt; &lt;/div&gt; </code></pre> <p>JS + Jquery:</p> <pre><code>$(function(){ $('#feature-links a').click(function() { if ($(this).hasClass('a-active')) { return false; } else { var image = $(this).attr('class'); switchToImg(image, function() { $('#feature-links a .a-active').removeClass('a-active'); $('#feature-links .' + image).addClass('a-active'); }); } }); function switchToImg(image){ $('#feature-image').fadeOut('300', function(){ $('#feature-image').css('background-image','url(images/main_' + image + '.jpg)'); $('#feature-image').fadeIn('300'); }); }; </code></pre> <p>In the script I check for a <code>click</code> on an <code>&lt;a&gt;</code> tag, each <code>&lt;a&gt;</code> tag has a class of (a1, a2, a3 etc.). Also, the active <code>&lt;a&gt;</code> has a class of 'a-active'.</p> <p>I'm attempting to check if <code>a-active</code> is set with this:</p> <pre><code>if ($(this).hasClass('a-active')) { return false; } </code></pre> <p>and cut the script there so that it doesn't fade in and out the same image. However, the image continues to fade in and out despite my return false on checking for the class <code>a-active</code> and returning false. I am sure the problem is in the section where I am using <code>.addClass</code> and <code>.removeClass</code> but my knowledge of Javascript and Jquery is to flaky for me to properly debug this. </p> <p>Could someone cast a critical eye over this please?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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. 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