Using Jquery's index() to search for a given element

Using Jquery's index() to search for a given element

I had the simple task today of toggling between content depending on what list item was selected.

As the content to be displayed was laid out in the same order as the list was displayed it was just a matter of getting the position of the selected list item and then showing the content in the corresponding div.

The listCount variable is saving the position of the selected list item using the .index() method. Next all of the content is hidden from site. lastly we use the listCount variable to select which content should be displayed.

Demo here

comments powered by Disqus