Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with jQuery .before
    primarykey
    data
    text
    <p>So I'm building a very simple carousel with 4 divs. It uses 2 jQuery functions to set a div to either first or last position. There is only alpha transitions as I don't need movement.</p> <p>For some reason, though I can access my divs with .eg(n) etc, but the first, last and other various numbers aren't working in this function.</p> <p>Code:</p> <pre><code>$('#prev').click(function() { $('.container .divname').animate({opacity: 0}, 1000,function(){ $('.container .divname:first').before($('.container .divname:last')); $('.container .divname').animate({opacity: 1}, 1000); }); return false; }); </code></pre> <p>So that function isn't working.</p> <pre><code>$('#prev').click(function() { $('.container .divname').animate({opacity: 0}, 1000,function(){ $('.container .divname:eq(0)').before($('.container .divname:eq(3)')); $('.container .divname').animate({opacity: 1}, 1000); }); return false; }); </code></pre> <p>This also doesn't work, but if I change the <strong>eq(3)</strong> to <strong>eq(2)</strong> it does, but obviously misses one of my divs. I can still access the eq(3) because I tested it, and made it's background red.</p> <pre><code>$('.container .divname:eq(3)').css({'background-color' : '#ff0000'}); </code></pre> <p>This works...</p> <p>Can anyone please tell me why this maybe happening?</p> <p>Html example is as below</p> <pre><code>&lt;html&gt; &lt;div class="container"&gt; &lt;div class="divname"&gt; &lt;p&gt;some content&lt;/p&gt; &lt;/div&gt; &lt;div class="divname"&gt; &lt;p&gt;some content&lt;/p&gt; &lt;/div&gt; &lt;div class="divname"&gt; &lt;p&gt;some content&lt;/p&gt; &lt;/div&gt; &lt;div class="divname"&gt; &lt;p&gt;some content&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/html&gt; </code></pre> <p><strong>EDIT:</strong></p> <p>I have changed all the id to class now for the w3c kids in the audience. Issue still resides.</p> <p><a href="http://jsfiddle.net/3P8t5/1/" rel="nofollow">http://jsfiddle.net/3P8t5/1/</a></p>
    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.
 

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