Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting index of an li in a ul?
    primarykey
    data
    text
    <p>I'm close to this but cross-brained on something.</p> <p>I have this code:</p> <pre><code>var numOfLi = $('#myList li').length; var lastLi = numOfLi; $('.next').click(function() { var current = $('#myList').find('li.on'); current.removeClass('on'); current.next().addClass('on'); var grabAlt = $('.on img').attr('alt').split('|'); var holdAlt = grabAlt; $('#altStuff').html('&lt;ul class="altDescription"&gt;' + '&lt;li&gt;' + holdAlt[0] + '&lt;/li&gt;' + '&lt;li&gt;' + holdAlt[1] + '&lt;/li&gt;' + '&lt;li&gt;' + holdAlt[2] + '&lt;/li&gt;' + '&lt;/ul&gt;'); }); $('.prev').click(function() { var current = $('#myList').find('li.on'); current.removeClass('on'); current.prev().addClass('on'); var grabAlt = $('.on img').attr('alt').split('|'); var holdAlt = grabAlt; $('#altStuff').html('&lt;ul class="altDescription"&gt;' + '&lt;li&gt;' + holdAlt[0] + '&lt;/li&gt;' + '&lt;li&gt;' + holdAlt[1] + '&lt;/li&gt;' + '&lt;li&gt;' + holdAlt[2] + '&lt;/li&gt;' + '&lt;/ul&gt;'); }); </code></pre> <p>It clicks forward and back through a list of Li's, assigns a class of 'on' to the li, grabs the alt text of the image in each Li, parses that and puts it into a paragraph.</p> <p>This all works great and dynamically, but now I'm trying to stop the next/prev buttons when they reach the first/last li.</p> <p>My thought is to: 1. upon clicking, check to see if the current li is the first one (don't let prev work) or the last one (don't let next work).</p> <p>But, I'm a little mushed now as to how to check that. The .length only returns the count....so, how can I get the position value of whatever the current li is?</p> <p>I was thinking I have to put all the li's of this ul into a matrix and then just check against it's index but I'm not getting that work.</p> <p>Thanks for looking.</p> <p>I was thinking I'd have to put the entire UL list into </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