Skip to content
Advertisement

Replace fetch link with html button

This code is designed to take a data from API, convert it to JSON and display it in the HTML page (with a specific design). There are two buttons on the HTML page that are for changing the page (to change the page, the URL sent to fetch needs to be changed by clicking the buttons (which is where my problem is(: )).

I want to display the first page when the page is loaded, the second page when the “Next” button is clicked, and the first page again when the “Previous” button is clicked.

First page : “https://reqres.in/api/users?page=1”. Second page : “https://reqres.in/api/users?page=2”.

JavaScript
JavaScript

Advertisement

Answer

you can save the page number in a data attribute and pass its value to the fetch link.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement