I am facing an issue with my simple "pagination" counter that fetches the next page from an API. The problem arises when I switch between different categories, such as movies or series, because the counter does not reset. Instead of starting again from the first page of the new category, it continues from where it left off.
Despite trying various conditional combinations, none have proven effective so far. I believe solving this should not be too difficult; however, I am struggling to think of the right logic to implement.
let page = 1;
document.getElementById('load-more').addEventListener('click', () => {
page++;
const movies = document.getElementById('movies');
const series = document.getElementById('series');
if(movies.classList.contains('active-link')) {
getMovies(page);
} else if (series.classList.contains('active-link')) {
getSeries(page);
}
})
Resetting the let counter inside the if..else statement does not work as expected, since clicking the load more button resets it back to page 1 each time.