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