Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy $('a.current').parent('li').addClass('current'); is not working?
    primarykey
    data
    text
    <p>Why <code>$('a.current').parent('li').addClass('current');</code> and <code>$(this).hasClass('current').parent('li').addClass('current');</code> are not working?</p> <p><code>a</code> click event must add <code>li.current</code> <a href="http://jsfiddle.net/laukstein/ytnw9/" rel="nofollow">http://jsfiddle.net/laukstein/ytnw9/</a></p> <blockquote> <p><strong>Update:</strong> Dropbox is Down, so I updated <a href="http://jsfiddle.net/laukstein/ytnw9/1/" rel="nofollow">http://jsfiddle.net/laukstein/ytnw9/1/</a> with full JS</p> </blockquote> <pre><code>$(function(){ var list=$('#list'), elementsPerRow=-1, loop=true, // find first image y-offset to find the number of images per row topOffset=list.find('a:eq(0)').offset().top, numTabs=list.find('li').length-1, current,newCurrent; function changeTab(diff){ // a.current set by jQuery Tools tab plugin current=list.find('a.current').parent('li').addClass('current').index(); newCurrent=(loop)?(current+diff+numTabs+1)%(numTabs+1):current+diff; if(loop){ if(newCurrent&gt;numTabs){newCurrent=0;} if(newCurrent&lt;0){newCurrent=numTabs;} }else{ if(newCurrent&gt;numTabs){newCurrent=numTabs;} if(newCurrent&lt;0){newCurrent=0;} } // don't trigger change if tab hasn't changed (for non-looping mode) if (current!=newCurrent){ list.find('li').eq(current).removeClass('current'); list.find('li').eq(newCurrent).addClass('current').find('a').trigger('click'); // trigger click on tab } } list // set up tabs .tabs("#content",{effect:'ajax',history:true}) // find number of images on first row .find('a').each(function(i){ // $(this).hasClass('current').parent('li').addClass('current'); if(elementsPerRow&lt;0&amp;&amp;$(this).offset().top&gt;topOffset){ elementsPerRow=i; } }); // Set up arrow keys // Set to document for demo, probably better to use #list in the final version. $(document).bind('keyup focus',function(e){ var key=e.keyCode; if(key&gt;36&amp;&amp;key&lt;41){ if(key==37){changeTab(-1);} // Left if(key==38){changeTab(-elementsPerRow);} // Up if(key==39){changeTab(+1);} // Right if(key==40){changeTab(+elementsPerRow);} // Down e.preventDefault(); } }); // toggle looping through tabs $(':button').click(function(){ loop=!loop; $('#loopStatus').text(loop); }); $('a.current').parent('li').addClass('current'); });​ </code></pre> <p><em>EDIT: Adding HTML from jsFiddle link that was omitted from question</em></p> <pre><code>&lt;button&gt;Loop&lt;/button&gt; &lt;span id="loopStatus"&gt;true&lt;/span&gt;&lt;br /&gt; &lt;ul id="list"&gt; &lt;li&gt;&lt;a class="current" href="http://dl.dropbox.com/u/6594481/tabs/one.html" title="one"&gt;1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/two.html" title="two"&gt;2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/three.html" title="three"&gt;3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/four.html" title="four"&gt;4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/five.html" title="five"&gt;5&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/six.html" title="six"&gt;6&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/seven.html" title="seven"&gt;7&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/eight.html" title="eight"&gt;8&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://dl.dropbox.com/u/6594481/tabs/nine.html" title="nine"&gt;9&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="content" style="clear:both;"&gt;Loading...&lt;/div&gt;​ </code></pre>
    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.
 

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