Ok, so I know how to get all the li items and indices, such as:
totalLi = $('.content li').length;
clck = $('li.content).index();
and writing something to allow clicking of any li, such as:
$(‘.content li’).click(function() {something})
and yet I can’t seem to figure out how I would:
“Click on any li in a given list, identify which it is, and based on that send a parameter to a function that would animate something else.”
The part I’m stuck on is that by using:
#(‘.content li’).click…. I don’t know how to pull the index value with a variable. I’m all over the place with “this” but alerting that only gets [object] returned so it’s to generic.
I’m guessing I should set the index to a variable but maybe not?
I’m wanting to have a dynamic routine so that whether there are 5 or 15 li’s, I can click on any of them and make something happen. The snapper is that I need to have a previous and next item. I can get those to appear easy enough, but iterating +1 or -1 seems like it would interfere with the li’s that are a, b, c, d etc. (instead of numbers, either way the list is just a navigation to go through the questions but any number could be clicked on… it’s not linear)
I’ve played with .each() and first/end etc.. I’m not getting it?
is this not working?
$('.content li').click()binds the click event on each li element. Then when you refer to$(this)it will direct to the element which has triggered the click event and you can directly use that element. It is up to you what you want : index(), text(), html() or any other attribute.