Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Young Choe
seal-mask
.a{fill-rule:evenodd;}techdegree
Young Choe
Python Web Development Techdegree Student 6,259 Points

Pagination Function is not working with Jquery

https://w.trhou.se/autr968emc

This is the snapshot of the HTML and CSS files.

function pagination(totalStudentsToSort) {
    const paginationNav = document.querySelector('.pagination ul');
    let totalPages = Math.ceil(totalStudentsToSort / 10);
    let paginationHTML = $();

    for (let i = 1; i <= totalPages; i++) {

        if (i === 1) {
            $(paginationHTML).html("<li> + <a class=\"active\" href=\"#\"> + i + </a> + </li>");
        } else {
            $(paginationHTML).html("<li> + <a href=\"#\"> + i + </a> + </li>");
        }

    }
    $(paginationNav).html(paginationHTML);
}

This is the function that is causing the page buttons to not show up in the browser.

1 Answer

Steven Parker
Steven Parker
231,275 Points

Why isn't the JavaScript included in the snapshot?

But a few issues stand out at first glance:

  • the code defines a function but never calls it
  • the function tries to select an element that does not exist in the HTML
  • the function also attempts to add HTML content to an empty jQuery object set
Steven Parker
Steven Parker
231,275 Points

There are a number of issues, here's a few hints to get you started:

  • "index.html" relies on two resources that are missing; "css/reset.css" and "js/jquery-3.3.1.min.js"
  • hiding the whole list (line 9) prevents any students from becoming visible on page selection
  • the argument given to "appendPageLinks" is a number, but it then tries to access a "length" property on it
  • "showPages" (line 47 of "app.js") is not defined
  • misspelling of "preventDefualt" on line 50 (instead of "preventDefault")