Html

<table class="table">
        <thead>
            <tr>
                <th scope="col">#</th>
                <th scope="col">Name</th>
                <th scope="col">Salary</th>
                <th scope="col">Age</th>
            </tr>
        </thead>
        <tbody class="page-data">


        </tbody>
    </table>
    <nav aria-label="Page navigation example">
        <ul class="pagination">
            <li onclick="prePage()" class="page-item page-list">
                <a class="page-link" href="#" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                    <span class="sr-only">Previous</span>
                </a>
            </li>

            <li onclick="nextPage()" class="page-item">
                <a class="page-link" href="#" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                    <span class="sr-only">Next</span>
                </a>
            </li>
        </ul>
    </nav>

JS Code

<script>
        let userData = null;
        $.ajax({
            url: "http://dummy.restapiexample.com/api/v1/employees",
            type: "get",
            async: false,
            success: function(users) {
                userData = users.data;
            }
        });
        var currentPage = 0;
        let pages = "";
        let page_size = 5;
        pages = paginate(userData, page_size);
        pageLi = "";
        pages.forEach((element, index) => {
            if (index != 0)
                pageLi += '<li onclick="pageChange(' + index + ')" id="page_' + index + '" class="page-item list-item" id="page_' + index + '"><a class="page-link" href="javascript:void(0)">' + index + '</a></li>';
        });
        $(".page-list").after(pageLi);
        page = pages[currentPage];
        printRows(page);

        function nextPage() {
            if (pages.length - 1 > currentPage)
                page = currentPage + 1;
            pageChange(page);
        }

        function prePage() {
            if (currentPage < pages.length && currentPage != 0)
                page = currentPage - 1;
            pageChange(page);
        }

        function pageChange(page) {
            currentPage = page;
            $(".list-item").removeClass("active");
            $("#page_" + page).addClass("active");
            $(".page-data").html("");
            page = pages[page];
            printRows(page);
        }

        function printRows(arr) {
            arr.forEach(element => {
                $(".page-data").append("<tr><td>" + element.id + "</td><td>" + element.employee_name + "</td><td>" + element.employee_salary + "</td><td>" + element.employee_age + "</td></tr>");

            });
        }

        function paginate(arr, size) {
            return arr.reduce((acc, val, i) => {
                let idx = Math.floor(i / size)
                let page = acc[idx] || (acc[idx] = [])
                page.push(val)
                return acc
            }, [])
        }
    </script>
Answer from Azad Education on Stack Overflow
🌐
Bootstrap
getbootstrap.com › docs › 4.0 › components › pagination
Pagination · Bootstrap
Pagination links are customizable for different circumstances. Use .disabled for links that appear un-clickable and .active to indicate the current page. While the .disabled class uses pointer-events: none to try to disable the link functionality of <a>s, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add tabindex="-1" on disabled links and use custom JavaScript to fully disable their functionality.
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › components › pagination
Pagination · Bootstrap v5.3
As such, you should always add tabindex="-1" on disabled links and use custom JavaScript to fully disable their functionality. ... <nav aria-label="..."> <ul class="pagination"> <li class="page-item disabled"> <a class="page-link">Previous</a> </li> <li class="page-item"><a class="page-link" href="#">1</a></li> <li class="page-item active"> <a class="page-link" href="#" aria-current="page">2</a> </li> <li class="page-item"><a class="page-link" href="#">3</a></li> <li class="page-item"> <a class="page-link" href="#">Next</a> </li> </ul> </nav>
🌐
W3Schools
w3schools.com › bootstrap › bootstrap_pagination.asp
Bootstrap Pagination
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › pagination
Pagination · Bootstrap v5.0
Pagination links are customizable for different circumstances. Use .disabled for links that appear un-clickable and .active to indicate the current page. While the .disabled class uses pointer-events: none to try to disable the link functionality of <a>s, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add tabindex="-1" on disabled links and use custom JavaScript to fully disable their functionality.
Top answer
1 of 2
4

Html

<table class="table">
        <thead>
            <tr>
                <th scope="col">#</th>
                <th scope="col">Name</th>
                <th scope="col">Salary</th>
                <th scope="col">Age</th>
            </tr>
        </thead>
        <tbody class="page-data">


        </tbody>
    </table>
    <nav aria-label="Page navigation example">
        <ul class="pagination">
            <li onclick="prePage()" class="page-item page-list">
                <a class="page-link" href="#" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                    <span class="sr-only">Previous</span>
                </a>
            </li>

            <li onclick="nextPage()" class="page-item">
                <a class="page-link" href="#" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                    <span class="sr-only">Next</span>
                </a>
            </li>
        </ul>
    </nav>

JS Code

<script>
        let userData = null;
        $.ajax({
            url: "http://dummy.restapiexample.com/api/v1/employees",
            type: "get",
            async: false,
            success: function(users) {
                userData = users.data;
            }
        });
        var currentPage = 0;
        let pages = "";
        let page_size = 5;
        pages = paginate(userData, page_size);
        pageLi = "";
        pages.forEach((element, index) => {
            if (index != 0)
                pageLi += '<li onclick="pageChange(' + index + ')" id="page_' + index + '" class="page-item list-item" id="page_' + index + '"><a class="page-link" href="javascript:void(0)">' + index + '</a></li>';
        });
        $(".page-list").after(pageLi);
        page = pages[currentPage];
        printRows(page);

        function nextPage() {
            if (pages.length - 1 > currentPage)
                page = currentPage + 1;
            pageChange(page);
        }

        function prePage() {
            if (currentPage < pages.length && currentPage != 0)
                page = currentPage - 1;
            pageChange(page);
        }

        function pageChange(page) {
            currentPage = page;
            $(".list-item").removeClass("active");
            $("#page_" + page).addClass("active");
            $(".page-data").html("");
            page = pages[page];
            printRows(page);
        }

        function printRows(arr) {
            arr.forEach(element => {
                $(".page-data").append("<tr><td>" + element.id + "</td><td>" + element.employee_name + "</td><td>" + element.employee_salary + "</td><td>" + element.employee_age + "</td></tr>");

            });
        }

        function paginate(arr, size) {
            return arr.reduce((acc, val, i) => {
                let idx = Math.floor(i / size)
                let page = acc[idx] || (acc[idx] = [])
                page.push(val)
                return acc
            }, [])
        }
    </script>
2 of 2
1

I suggest you use bootpag,

It's very simple and works good with bootstrap, it also has good documentation to show you how to use it step by step.
I don't have to explain it here since everything is explained on the website.

I hope this can help you.

Link: http://botmonster.com/jquery-bootpag/#pro-page-8

🌐
Jacobmarshall-etc
jacobmarshall-etc.github.io › bootstrap-paginator
Bootstrap Paginator - Bootstrap Pagination jQuery plugin
Bootstrap Paginator is a jQuery plugin that simplifies the rendering of Bootstrap Pagination component. It provides methods to automates the update of the pagination status and also some events to notify the status changes within the component.
🌐
Bootstrap
getbootstrap.com › docs › 5.2 › components › pagination
Pagination · Bootstrap v5.2
Pagination links are customizable for different circumstances. Use .disabled for links that appear un-clickable and .active to indicate the current page. While the .disabled class uses pointer-events: none to try to disable the link functionality of <a>s, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add tabindex="-1" on disabled links and use custom JavaScript to fully disable their functionality.
🌐
TutorialsPoint
tutorialspoint.com › bootstrap › bootstrap_pagination.htm
Bootstrap - Pagination
In order to create a basic pagination, add the .pagination class to an <ul> element. To each <li> element add the .page-item and a .page-link class to the link inside it. You can edit and try running this code using the Edit & Run option.
Find elsewhere
🌐
React Bootstrap
react-bootstrap.netlify.app › pagination
Pagination | React Bootstrap
import Pagination from 'react-bootstrap/Pagination'; let active = 2; let items = []; for (let number = 1; number <= 5; number++) { items.push( <Pagination.Item key={number} active={number === active}> {number} </Pagination.Item>, ); } const paginationBasic = ( <div> <Pagination>{items}</Pagination> <br /> <Pagination size="lg">{items}</Pagination> <br /> <Pagination size="sm">{items}</Pagination> </div> ); render(paginationBasic); For building more complex pagination UI, there are few convenient sub-components for adding "First", "Previous", "Next", and "Last" buttons, as well as an "Ellipsis" item for indicating previous or continuing results.
🌐
jQuery Script
jqueryscript.net › jquery plugins › jquery other plugins
Dynamic Paging System In jQuery And Bootstrap - Simple Pagination | Free jQuery Plugins
Stackable Offcanvas Panel Plugin for Bootstrap 5 - jQuery bs-layer · Client-side Pagination Plugin for Static Content - jQuery SimplePaginate.js
🌐
W3Schools
w3schools.com › bootstrap4 › bootstrap_pagination.asp
Bootstrap 4 Pagination
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
MDBootstrap
mdbootstrap.com › standard › pagination
Bootstrap Pagination - free examples & tutorial
Responsive pagination and pager built with Bootstrap 5.With this component, you can spread your content over many pages. Learn how to build pagination with free code examples.
🌐
Esimakin
esimakin.github.io › twbs-pagination
jQuery Pagination plugin
$('.sync-pagination').twbsPagination({ totalPages: 20, onPageClick: function (evt, page) { $('#content').text('Page ' + page); } }); ... It shows how it look like with bootstrap 4 (version 4.0.0-alpha.4).
Top answer
1 of 1
4

When I navigate the pages with the arrows (not the numbers), the numbers dont get the "active" class, and I couldnt figurate how to make it.

You should first check which "number" is actualy active, then add active class the next number (if pag_next is clicked) or to the previous number (if pag_prev is clicked).

$(".pagination li.pag_prev").click(function() {
    // ...
    // instead of this (as "this" is the arrow):
    // $(this).addClass("active");
    // remove active class of the current number and add the class to previous number:
    $('.numeros.active').removeClass('active').prev().addClass('active');

    // ...
});

$(".pagination li.pag_next").click(function() {
    // ...
    // instead of this (as "this" is the arrow):
    // $(this).addClass("active");
    // remove active class of the current number and add the class to next number:
    $('.numeros.active').removeClass('active').next().addClass('active');

    // ...
});

Im showing 5 pages, but you can navigate to infinite foward and backward, i don't know how to tell to stop when reach the last and the first page.

You should simply check if the first or last pagination number already has class active, then return (do nothing) if one of them has:

$(".pagination li.pag_prev").click(function() {
    // make sure that the active pagination number is not the first.
    // we want to return here (do nothing) if the first number is already active:
    if($(this).next().is('.active')) return;
    // ...
    // continue executing if the first number isn't yet active:
    currentPage--;
    showPage();
});

$(".pagination li.pag_next").click(function() {
    // make sure that the active pagination number is not the last.
    // we want to return here (do nothing) if the last number is already active:
    if($(this).prev().is('.active')) return;
    // ...
    // continue executing if the last number isn't yet active:
    currentPage++;
    showPage();
});

Is there a way to automatic generate a new Nº and the respective page with JS when the page reach the amount of news setting (e.x. pageSize = 5)?

Yes.

First, we need some more variables:

// news per page:
var pageSize = 1;
// total news (count elements with "content" class):
var pagesCount = $(".content").length;
// calculate total pages:
var totalPages = Math.ceil(pagesCount / pageSize);

// I have replaced "i" variable with "currentPage" (more details at the bottom)
var currentPage = 1;

We already know the totalPages and pageSize, so we can create pagination dynamically based on total amount of news and the number of news per page:

HTML:

<ul class="pagination">
    <li class="pag_prev">
        <a href="#" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span>
        </a>
    </li>
    <!-- our dynamic pagination content goes here -->
    <li class="pag_next">
        <a href="#" aria-label="Next">
            <span aria-hidden="true">&raquo;</span>
        </a>
    </li>
</ul>

JS:

var nav = '';
for (var s=0; s<totalPages; s++){
    nav += '<li class="numeros"><a href="#">'+(s+1)+'</a></li>';
}
// append pagination numbers after "prev" button:
$(".pag_prev").after(nav);
// add "active" class to the first pagination number:
$(".numeros").first().addClass("active");

As a side note, your i variable is set in a global scope, so you don't have to pass it every time to the showPage() method and you can use it direclty.
I renamed this variable to something more "readable" - currentPage:

var currentPage = 1;

showPage = function() {
    $(".content").hide().each(function(n) {
        if (n >= pageSize * (currentPage - 1) && n < pageSize * currentPage)
            $(this).show();
    });
}

showPage();

Whole code on JSFiddle

🌐
W3Schools
w3schools.com › bootstrap5 › bootstrap_pagination.php
Bootstrap 5 Pagination
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.
🌐
GitHub
github.com › markbates › jquery-bootstrap-pagination
GitHub - markbates/jquery-bootstrap-pagination
// Basic usage: $("#my-pagination-section").pagination(); // With options: $("#my-pagination-section").pagination({ total_pages: 10, current_page: 2, callback: function(event, page) { return alert("Page " + page + " was clicked!"); } }); // ...
Starred by 90 users
Forked by 39 users
Languages   CoffeeScript 85.8% | Ruby 14.2% | CoffeeScript 85.8% | Ruby 14.2%
🌐
Educative
educative.io › answers › how-to-use-bootstrap-pagination
How to use Bootstrap pagination
Line 15: We add the pagination class to the <ul> HTML element and this <ul> wraps every other <li> . The pagination bootstrap class styles the <ul> element.
🌐
CoreUI
coreui.io › react › documentation › components › pagination
Bootstrap Pagination - extended examples and tutorials
July 5, 2023 - Pagination links are customizable for different circumstances. Use .disabled for links that appear un-clickable and .active to indicate the current page. While the .disabled class uses pointer-events: none to try to disable the link functionality of <a>s, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add tabindex="-1" on disabled links and use custom JavaScript to fully disable their functionality.
🌐
Bootstrap
getbootstrap.com › docs › 4.6 › components › pagination
Pagination · Bootstrap v4.6
Pagination links are customizable for different circumstances. Use .disabled for links that appear un-clickable and .active to indicate the current page. While the .disabled class uses pointer-events: none to try to disable the link functionality of <a>s, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add tabindex="-1" on disabled links and use custom JavaScript to fully disable their functionality.
🌐
PureCode AI
blogs.purecode.ai › home › bootstrap pagination: how to create engaging user experience
Bootstrap Pagination: How to Create Engaging User Experience - Blogs
September 2, 2025 - The code above lays the groundwork for implementing Bootstrap Pagination in the guide. The <link> tag includes the Bootstrap CSS file, providing the styling and layout for Bootstrap components, and the <script> tag includes the Bootstrap JavaScript files.