Both the jQuery and Prototpye JavaScript libraries refuse to allow me to use a variable to select an list item element by index number although they accept a hard coded number.
For example, in Prototype this works:
$$('li')[5].addClassName('active');
But this will not work no matter how I try to cast the variable as a number or integer:
$$('li')[currentPage].addClassName('active');
In jQuery I get similar weirdness. This will work:
jQuery('li').eq(5).addClass("active");
But this will not work again even though the value of currentPage is 5 and its type is number:
jQuery('li').eq(currentPage).addClass("active");
I'm trying to create a JavaScript pagination system and I need to set the class on the active page button. The list item elements are created dynamically depending upon the number of pages I need.