<script defer>
let url = "https://gorest.co.in/public-api/posts?page=1";
let p;
document.getElementById("btnF").addEventListener("click", function () {
url = "https://gorest.co.in/public-api/posts?page=2";
Removez();
Load();
});
let data;
let arr2 = []; // список оглавлений
console.log(arr2);
function Removez() {
let v = document.getElementsByTagName("p");
console.log(v);
while (v.length > 0) v[0].remove();
}
async function Load() {
let response = await fetch(url);
console.log(response.url);
data = await response.json();
console.log(data);
let TotalPagesValue = data["meta"]["pagination"]["pages"]; //общее страниц количество
let TotalPageValue = data["meta"]["pagination"]["page"]; //общее статей количество
console.log(TotalPagesValue);
console.log(TotalPageValue);
let KeysOfHeader = data["data"];
let parent = document.getElementById("parent");
for (let key in KeysOfHeader) {
let AllHeaders = KeysOfHeader[key]["title"];
console.log(AllHeaders);
arr2.push(AllHeaders);
}
let x = 0;
for (let i = 1; i <= arr2.length; i++) {
p = document.createElement("p");
p.className = "par";
p.textContent = arr2[x];
x = x + 1;
parent.appendChild(p);
}
}
Load();
</script>