Back to all resources
Pagination
Asynchronous Programming
Event Listener
Fetch API

Wes Pagination

By Jared Malan
This script is responsible for handling pagination on Wes, a Edgar Allan product. It fetches content from the next or previous page without reloading the entire page, providing a smoother user experience. 

The script begins by creating a hidden div element in the body of the document. This div is used to store the fetched content temporarily. 

The fetchContent function is the main function of this script. It is an asynchronous function that is triggered when a user clicks on the "next" or "previous" pagination button. The function prevents the default action of the button, fetches the content of the next or previous page, and replaces the current content with the fetched content. 

The setupNextButton and setupPreviousButton functions add click event listeners to the "next" and "previous" buttons respectively. These functions are called at the end of the script to initialize the pagination functionality.