Question: How can I  put and show images to the page 1   JS-> // selecting required element const element = document.querySelector(".pagination ul"); let totalPages = 10; let page = 2; //calling function with passing parameters and adding inside element which is ul tag element.innerHTML = createPagination(totalPages, page); function createPagination(totalPages, page){   let liTag = '';   let active;   let beforePage = page - 1;   let afterPage = page + 1;   if(page > 1){ //show the next button if the page value is greater than 1     liTag += Prev;   }   // how many pages or li show before the current li   if (page == totalPages) {     beforePage = beforePage - 2;   } else if (page == totalPages - 1) {     beforePage = beforePage - 1;   }   // how many pages or li show after the current li   if (page == 1) {     afterPage = afterPage + 2;   } else if (page == 2) {     afterPage  = afterPage + 1;   }   for (var plength = beforePage; plength <= afterPage; plength++) {     if (plength > totalPages) { //if plength is greater than totalPage length then continue       continue;     }     if (plength == 0) { //if plength is 0 than add +1 in plength value       plength = plength + 1;     }     if(page == plength){ //if page is equal to plength than assign active string in the active variable       active = "active";     }else{ //else leave empty to the active variable       active = "";     }     liTag += ${p≤n>h};   }   if (page < totalPages) { //show the next button if the page value is less than totalPage(20)     liTag += Next;   }   element.innerHTML = liTag; //add li tag inside ul tag   return liTag; //reurn the li tag }   HTML->             Pagination in JavaScript | CodingNepal

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Question: How can I  put and show images to the page 1

 

JS->


// selecting required element
const element = document.querySelector(".pagination ul");
let totalPages = 10;
let page = 2;

//calling function with passing parameters and adding inside element which is ul tag
element.innerHTML = createPagination(totalPages, page);
function createPagination(totalPages, page){
  let liTag = '';
  let active;
  let beforePage = page - 1;
  let afterPage = page + 1;
  if(page > 1){ //show the next button if the page value is greater than 1
    liTag += <liclass=btn prevonclick=createPagination(totalPages, ${page - 1})><span><iclass=fas fa-angle-left><i>Prev<span><li>;
  }

  // how many pages or li show before the current li
  if (page == totalPages) {
    beforePage = beforePage - 2;
  } else if (page == totalPages - 1) {
    beforePage = beforePage - 1;
  }
  // how many pages or li show after the current li
  if (page == 1) {
    afterPage = afterPage + 2;
  } else if (page == 2) {
    afterPage  = afterPage + 1;
  }

  for (var plength = beforePage; plength <= afterPage; plength++) {
    if (plength > totalPages) { //if plength is greater than totalPage length then continue
      continue;
    }
    if (plength == 0) { //if plength is 0 than add +1 in plength value
      plength = plength + 1;
    }
    if(page == plength){ //if page is equal to plength than assign active string in the active variable
      active = "active";
    }else{ //else leave empty to the active variable
      active = "";
    }
    liTag += <liclass=numb ${active}onclick=createPagination(totalPages, ${plength})><span>${p≤n>h}<span><li>;
  }

  if (page < totalPages) { //show the next button if the page value is less than totalPage(20)
    liTag += <liclass=btn nextonclick=createPagination(totalPages, ${page + 1})><span>Next<iclass=fas fa-angle-right><i><span><li>;
  }
  element.innerHTML = liTag; //add li tag inside ul tag
  return liTag; //reurn the li tag
}

 

HTML->


<!DOCTYPE html>
<!-- Coding By CodingNepal - youtube.com/codingnepal -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pagination in JavaScript | CodingNepal</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<body>
  <div class="pagination">
    <ul> <!--pages or li are comes from javascript --> 
       
    </ul>
  </div>
  </div>
  <script src="script.js"></script>

</body>
</html>

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education