{"id":5505,"date":"2023-03-10T12:45:08","date_gmt":"2023-03-10T17:45:08","guid":{"rendered":"https:\/\/www.cloudsurph.com\/?p=5505"},"modified":"2023-03-10T12:45:31","modified_gmt":"2023-03-10T17:45:31","slug":"pagination-in-vanilla-javascript","status":"publish","type":"post","link":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/","title":{"rendered":"Pagination in Vanilla JavaScript"},"content":{"rendered":"<p>In this article, we try to show an example of post pagination or navigation created by JavaScript.<\/p>\n<p>So, let\u2019s see the article for Pagination in Vanilla JavaScript, how to create a custom post pagination with JavaScript, Fetching REST API Posts, how to Implement Pagination in JavaScript, Implementing Pagination Logic and posts pagination with JavaScript.<\/p>\n<h2>How to create a custom post pagination with JavaScript<\/h2>\n<p>In this case, when we create a website or web application, especially if they feature a lot of template\u00a0content and it\u2019s generally a good idea is divided it into pages\u00a0to reduce the number of items that appear on the screen at once.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/Custom-Post-Pagination-with-JavaScript.png\" alt=\"Custom Post Pagination with JavaScript.png\" width=\"1920\" height=\"854\" class=\"aligncenter size-full wp-image-5507\" srcset=\"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/Custom-Post-Pagination-with-JavaScript.png 1920w, https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/Custom-Post-Pagination-with-JavaScript-1280x569.png 1280w, https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/Custom-Post-Pagination-with-JavaScript-980x436.png 980w, https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/Custom-Post-Pagination-with-JavaScript-480x214.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 1920px, 100vw\" \/><\/p>\n<h5><em><strong>If you want then buy a good, reliable, secure web\u00a0<a href=\"https:\/\/www.cloudsurph.com\/windows-vps-hosting\/\">hosting<\/a>\u00a0service \u00a0from here:\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">click here<\/a><\/strong><\/em><\/h5>\n<p>For the purpose of our example, we are using fetch the content from this\u00a0<a href=\"https:\/\/jsonplaceholder.typicode.com\/posts\">example API<\/a> response.<\/p>\n<h3>Previous JavaScript Articles<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.cloudsurph.com\/javascript-variables\/\" aria-current=\"page\">JavaScript Variables<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/javascript-operators\/\">JavaScript Operators<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/creating-an-object-in-javascript\/\">Creating an Object in JavaScript<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/what-is-asynchronous-javascript\/\">Introduction to Asynchronous JavaScript<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/what-is-control-flow-in-javascript\/\">Control Flow in JavaScript<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/how-to-use-regex-in-javascript-function\/\">What is JavaScript Regex?<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/javascript-events-example\/\" aria-current=\"page\">JavaScript Events Example<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/how-to-create-a-preloader-in-javascript\/\" aria-current=\"page\">How to create a preloader in JavaScript?<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/foreach-method-in-javascript\/\" aria-current=\"page\">forEach method in JavaScript<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/sorting-arrays-in-javascript\/\" aria-current=\"page\">Sorting Arrays in JavaScript<\/a><\/li>\n<li><a href=\"https:\/\/www.cloudsurph.com\/what-is-linear-search-in-javascript\/\" aria-current=\"page\">Linear Search in JavaScript<\/a><\/li>\n<\/ul>\n<h3>Pagination in Vanilla JavaScript<\/h3>\n<p>Firstly, we create our template and then fetch all required posts from the API using the browser\u2019s built-in Fetch API.<\/p>\n<p>Hence, we first need to create a basic HTML markup template that will be dynamically filled via our JavaScript later<\/p>\n<pre class=\"prettyprint\">\r\n&lt;section class=\"pt-2\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"container\"&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"title-section\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;h1 class=\"title\"&gt;Custom Post Pagination with JavaScript&lt;\/h1&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"posts-section row\"&gt;&lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"pagination-section\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;ul class=\"pagination\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;li class=\"page-item prev\"&gt;&lt;a class=\"page-link\" href=\"#\"&gt;Previous&lt;\/a&gt;&lt;\/li&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;li class=\"page-item next\"&gt;&lt;a class=\"page-link\" href=\"#\"&gt;Next&lt;\/a&gt;&lt;\/li&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n \u00a0 &lt;\/section&gt;\r\n<\/pre>\n<h3>Fetching REST API Posts<\/h3>\n<p>As mentioned before, we require you to fetch the data, calculate the number of pages, decide when and how to split, and then show a portion of it to the user.<\/p>\n<p>Let&#8217;s get started by first fetching from all our posts and then later we will amend this to query only a few data points per page:<\/p>\n<pre class=\"prettyprint\">\r\nconst postsSection = document.querySelector(\".posts-section\");\r\n\u00a0 \u00a0 \u00a0 \u00a0 const fetchPosts = async (pageNumber) =&gt; {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const response = await fetch(\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"https:\/\/jsonplaceholder.typicode.com\/posts\"\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 );\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const posts = await response.json();\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 postsSection.innerHTML = \"\";\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 posts.forEach((post) =&gt; {\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 postsSection.innerHTML += `\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"posts-card col-md-4\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"post-item\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"post-title\"&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;h2 class=\"post-title-text\"&gt;${post.title}&lt;\/h2&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"post-body\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;p class=\"post-body-text\"&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ${post.body}\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/p&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 `;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 });\r\n\u00a0 \u00a0 \u00a0 \u00a0 };\r\n\u00a0 \u00a0 \u00a0 \u00a0 fetchPosts();\r\n<\/pre>\n<h3>How to Implement Pagination in JavaScript<\/h3>\n<p>In this situation, we need first one is the number of posts that we want to declare per page and then the current page number (1 by default), and the total number of pages. Here we give the total number of pages a fixed number of 30<\/p>\n<pre class=\"prettyprint\">\r\nconst numberPerPage = 6;\r\nvar pageNumber = 1;\r\nvar numberOfPages = 30;\r\n<\/pre>\n<p>Secondly, here we making use of these parameters by <strong>ammending<\/strong> our fetch request like below the code<\/p>\n<pre class=\"prettyprint\">\r\nconst postsSection = document.querySelector(\".posts-section\");\r\n\u00a0 \u00a0 \u00a0 \u00a0 const fetchPosts = async (pageNumber) =&gt; {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const response = await fetch(\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 `https:\/\/jsonplaceholder.typicode.com\/posts?_page=${pageNumber}&amp;_limit=${numberPerPage}`\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 );\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const posts = await response.json();\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 postsSection.innerHTML = \"\";\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 posts.forEach((post) =&gt; {\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 postsSection.innerHTML += `\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"posts-card col-md-4\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"post-item\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"post-title\"&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;h2 class=\"post-title-text\"&gt;${post.title}&lt;\/h2&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;div class=\"post-body\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;p class=\"post-body-text\"&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ${post.body}\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/p&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 `;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 });\r\n\u00a0 \u00a0 \u00a0 \u00a0 };\r\n\u00a0 \u00a0 \u00a0 \u00a0 fetchPosts();\r\n<\/pre>\n<h3>Implementing Pagination Logic<\/h3>\n<p>Now we create the pagination button by the below code to our application template<\/p>\n<h5><em><strong>If you want then buy a good, reliable, secure web\u00a0<a href=\"https:\/\/www.cloudsurph.com\/windows-vps-hosting\/\">hosting<\/a>\u00a0service \u00a0from here:\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">click here<\/a><\/strong><\/em><\/h5>\n<pre class=\"prettyprint\">\r\n&lt;div class=\"pagination-section\"&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;ul class=\"pagination\"&gt;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;li class=\"page-item prev\"&gt;&lt;a class=\"page-link\" href=\"#\"&gt;Previous&lt;\/a&gt;&lt;\/li&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;li class=\"page-item next\"&gt;&lt;a class=\"page-link\" href=\"#\"&gt;Next&lt;\/a&gt;&lt;\/li&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/div&gt;\r\n<\/pre>\n<h4>Implementing Previous Button<\/h4>\n<p>Now we add the <strong>CLICK<\/strong> event listener, to it and show the appropriate content when the button is clicked like the below code<\/p>\n<pre class=\"prettyprint\">\r\n\/\/ Add event listeners to the prev button\r\n\u00a0 \u00a0 \u00a0 \u00a0 const prev = document.querySelector('.prev');\r\n \u00a0 \u00a0 \u00a0 prev.addEventListener('click', (e) =&gt; {\r\n\u00a0 \u00a0 \u00a0 \u00a0 e.preventDefault();\r\n\u00a0 \u00a0 \u00a0 \u00a0 if (pageNumber &gt; 1) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 pageNumber--;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 fetchPosts(pageNumber);\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 });\r\n<\/pre>\n<h4>Implementing Next Button<\/h4>\n<p>Now we add the <strong>CLICK<\/strong> event listener, to it and show the appropriate content when the button is clicked like the below code<\/p>\n<h5><em><strong>If you want then buy a good, reliable, secure web\u00a0<a href=\"https:\/\/www.cloudsurph.com\/windows-vps-hosting\/\">hosting<\/a>\u00a0service \u00a0from here:\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">click here<\/a><\/strong><\/em><\/h5>\n<pre class=\"prettyprint\">\r\n\/\/ Add event listeners to the next button\r\n \u00a0 \u00a0 \u00a0 const next = document.querySelector(\".next\");\r\n\u00a0 \u00a0 \u00a0 \u00a0 next.addEventListener(\"click\", (e) =&gt; {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 e.preventDefault();\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (pageNumber &lt; numberOfPages) {\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 pageNumber++;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 fetchPosts(pageNumber);\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 });\r\n<\/pre>\n<h5>Lastly, we can just add some CSS for design our page template<\/h5>\n<h5><em><strong>You can purchase your\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">hosting from Cloudsurph.com<\/a>,\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">Cloudsurph hosting<\/a>\u00a0is a reliable hosting option for business and personal projects. We offer insight and help on system configuration issues and code errors or bugs<\/strong>.<\/em><\/h5>\n<pre class=\"prettyprint\">\r\n&lt;style&gt;\r\n\u00a0 \u00a0 \u00a0 \u00a0 body{background: #f1f1f1;}\r\n \u00a0 \u00a0 \u00a0 .title-section h1{font-size:24px;padding-bottom: 10px;line-height: 30px;}\r\n \u00a0 \u00a0 \u00a0 .post-item{\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 background: #fff;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 color: #000;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 padding: 10px;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 margin-bottom: 20px;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 border-radius: 10px;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 box-shadow: 5px 5px 3px #aaa;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 text-align: center;\r\n \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 .post-item h2{\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 font-size: 18px;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 line-height: 24px;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 border-bottom: 1px solid #ccc;\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 padding-bottom: 10px;\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 .post-item p{\r\n \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 font-size:14px;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 line-height: 20px;\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 &lt;\/style&gt;\r\n<\/pre>\n<p>Finally, open your HTML file in your browser. Also, I attached a zip file for your help, so please click the\u00a0<a href=\"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/custom_pagination_JavaScript.zip\">download link<\/a>\u00a0to get JavaScript preloader resources.<\/p>\n<h3><a href=\"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/custom_pagination_JavaScript.zip\">ClICK HERE FOR DOWNLOAD THE FILE &gt;&gt;<\/a><\/h3>\n<p>That\u2019s it. If you enjoyed reading this article and have more questions please reach out to our\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/submitticket.php?step=2&amp;deptid=1\">support team<\/a>\u00a0via live chat or\u00a0<a href=\"mailto:support@cloudsurph.com\">email<\/a>\u00a0and we would be glad to help you. we provide server\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">hosting<\/a>\u00a0for all types of need and we can even get your\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">server<\/a>\u00a0up and running with the service of your choice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we try to show an example of post pagination or navigation created by JavaScript. So, let\u2019s see the article for Pagination in Vanilla JavaScript, how to create a custom post pagination with JavaScript, Fetching REST API Posts, how to Implement Pagination in JavaScript, Implementing Pagination Logic and posts pagination with JavaScript. How [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":5506,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[157,25,162,159,44,1],"tags":[54,47,105,103,48,113],"class_list":["post-5505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-7","category-web-hosting-virtualization","category-javascript","category-linux-server","category-kvm-xen","category-virtual-private-servers","tag-best-vps-hosting-server-maryland","tag-cheap-cloud-servers","tag-cheap-storage-server-hosting","tag-cheapest-vps","tag-dedicated-server-hosting-in-washington-d-c","tag-speed-test-vps"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create a custom post pagination with JavaScript<\/title>\n<meta name=\"description\" content=\"Pagination in Vanilla JavaScript, How to create a custom post pagination with JavaScript, How to Implement Pagination in JavaScript\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create a custom post pagination with JavaScript\" \/>\n<meta property=\"og:description\" content=\"Pagination in Vanilla JavaScript, How to create a custom post pagination with JavaScript, How to Implement Pagination in JavaScript\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudsurph Web Hosting Washington D.C.\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/CloudSurph\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-10T17:45:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-10T17:45:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1264\" \/>\n\t<meta property=\"og:image:height\" content=\"760\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rony\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cloudsurph\" \/>\n<meta name=\"twitter:site\" content=\"@Cloud_Surph\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rony\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/\"},\"author\":{\"name\":\"Rony\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/person\\\/ac9b4dd136d96e50d5f29c560191e7ed\"},\"headline\":\"Pagination in Vanilla JavaScript\",\"datePublished\":\"2023-03-10T17:45:08+00:00\",\"dateModified\":\"2023-03-10T17:45:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/\"},\"wordCount\":608,\"publisher\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg\",\"keywords\":[\"Best VPS hosting server Maryland\",\"Cheap Cloud Servers\",\"Cheap Storage Server Hosting\",\"Cheapest VPS\",\"Dedicated Server Hosting in Washington D.C\",\"Speed test VPS\"],\"articleSection\":[\"CentOS 7\",\"Cloud Hosting\",\"JavaScript\",\"Linux Server\",\"Virtualization\",\"VPS Servers\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/\",\"name\":\"How to create a custom post pagination with JavaScript\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg\",\"datePublished\":\"2023-03-10T17:45:08+00:00\",\"dateModified\":\"2023-03-10T17:45:31+00:00\",\"description\":\"Pagination in Vanilla JavaScript, How to create a custom post pagination with JavaScript, How to Implement Pagination in JavaScript\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg\",\"contentUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg\",\"width\":1264,\"height\":760,\"caption\":\"How to create a custom post pagination with JavaScript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/pagination-in-vanilla-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cloudsurph.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pagination in Vanilla JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#website\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/\",\"name\":\"Cloudsurph Web Hosting Washington D.C.\",\"description\":\"Dedicated Server Hosting\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.cloudsurph.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#organization\",\"name\":\"CloudSurph Technology Solutions\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2016\\\/04\\\/cloudsurph-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2016\\\/04\\\/cloudsurph-logo.png\",\"width\":2348,\"height\":1692,\"caption\":\"CloudSurph Technology Solutions\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/CloudSurph\\\/\",\"https:\\\/\\\/x.com\\\/Cloud_Surph\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/person\\\/ac9b4dd136d96e50d5f29c560191e7ed\",\"name\":\"Rony\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g\",\"caption\":\"Rony\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/cloudsurph\"],\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/author\\\/ron\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create a custom post pagination with JavaScript","description":"Pagination in Vanilla JavaScript, How to create a custom post pagination with JavaScript, How to Implement Pagination in JavaScript","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to create a custom post pagination with JavaScript","og_description":"Pagination in Vanilla JavaScript, How to create a custom post pagination with JavaScript, How to Implement Pagination in JavaScript","og_url":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/","og_site_name":"Cloudsurph Web Hosting Washington D.C.","article_publisher":"https:\/\/www.facebook.com\/CloudSurph\/","article_published_time":"2023-03-10T17:45:08+00:00","article_modified_time":"2023-03-10T17:45:31+00:00","og_image":[{"width":1264,"height":760,"url":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg","type":"image\/jpeg"}],"author":"Rony","twitter_card":"summary_large_image","twitter_creator":"@cloudsurph","twitter_site":"@Cloud_Surph","twitter_misc":{"Written by":"Rony","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/#article","isPartOf":{"@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/"},"author":{"name":"Rony","@id":"https:\/\/www.cloudsurph.com\/#\/schema\/person\/ac9b4dd136d96e50d5f29c560191e7ed"},"headline":"Pagination in Vanilla JavaScript","datePublished":"2023-03-10T17:45:08+00:00","dateModified":"2023-03-10T17:45:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/"},"wordCount":608,"publisher":{"@id":"https:\/\/www.cloudsurph.com\/#organization"},"image":{"@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg","keywords":["Best VPS hosting server Maryland","Cheap Cloud Servers","Cheap Storage Server Hosting","Cheapest VPS","Dedicated Server Hosting in Washington D.C","Speed test VPS"],"articleSection":["CentOS 7","Cloud Hosting","JavaScript","Linux Server","Virtualization","VPS Servers"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/","url":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/","name":"How to create a custom post pagination with JavaScript","isPartOf":{"@id":"https:\/\/www.cloudsurph.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg","datePublished":"2023-03-10T17:45:08+00:00","dateModified":"2023-03-10T17:45:31+00:00","description":"Pagination in Vanilla JavaScript, How to create a custom post pagination with JavaScript, How to Implement Pagination in JavaScript","breadcrumb":{"@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/#primaryimage","url":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg","contentUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2023\/03\/How-to-create-a-custom-post-pagination-with-JavaScript.jpg","width":1264,"height":760,"caption":"How to create a custom post pagination with JavaScript"},{"@type":"BreadcrumbList","@id":"https:\/\/www.cloudsurph.com\/pagination-in-vanilla-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cloudsurph.com\/"},{"@type":"ListItem","position":2,"name":"Pagination in Vanilla JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.cloudsurph.com\/#website","url":"https:\/\/www.cloudsurph.com\/","name":"Cloudsurph Web Hosting Washington D.C.","description":"Dedicated Server Hosting","publisher":{"@id":"https:\/\/www.cloudsurph.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cloudsurph.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.cloudsurph.com\/#organization","name":"CloudSurph Technology Solutions","url":"https:\/\/www.cloudsurph.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudsurph.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2016\/04\/cloudsurph-logo.png","contentUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2016\/04\/cloudsurph-logo.png","width":2348,"height":1692,"caption":"CloudSurph Technology Solutions"},"image":{"@id":"https:\/\/www.cloudsurph.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/CloudSurph\/","https:\/\/x.com\/Cloud_Surph"]},{"@type":"Person","@id":"https:\/\/www.cloudsurph.com\/#\/schema\/person\/ac9b4dd136d96e50d5f29c560191e7ed","name":"Rony","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g","caption":"Rony"},"sameAs":["https:\/\/x.com\/cloudsurph"],"url":"https:\/\/www.cloudsurph.com\/author\/ron\/"}]}},"_links":{"self":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts\/5505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/comments?post=5505"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts\/5505\/revisions"}],"predecessor-version":[{"id":5510,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts\/5505\/revisions\/5510"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/media\/5506"}],"wp:attachment":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/media?parent=5505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/categories?post=5505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/tags?post=5505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}