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 Pagination & Content Filter

Jesus Marco del Carmen
Jesus Marco del Carmen
10,393 Points

Project 2 of FSJS Techdegree How do I show the object through jQuery?

Hi! I have already added a click handler on the page numbers, and have selected the appropriate list-items depending on page number. I can log the list-items into the console when I click the page, but I can't show the list-items on the page once I click. I've tried .show(); still doesn't work.

Here's my code

//Create pagination numbers depending on $numberOfStudents //create pagination div var $page = $('.page'); var $paginationDiv = $('<div class="pagination"></div>'); var $paginationUl = $('<ul></ul>'); for (var i = 0; i < Math.ceil($numberOfStudents/10); i++) { var $paginationLi = $('<li><a href="#"></a></li>'); $paginationLi.children().text(i+1); $paginationUl.append($paginationLi); } //append to appropriately $paginationDiv.append($paginationUl); $page.append($paginationDiv);

//Show 10 students depending on page number $studentList.hide(); $('.pagination li a').click(showStudents);

function showStudents () { var number = parseInt($(this).text()); var firstStudent = (((number - 1) * 10 ) + 1); var lastStudent = (number * 10); for (var i = firstStudent; i <= lastStudent; i++) { $studentList.children()[i]; } }

1 Answer

Steven Parker
Steven Parker
229,771 Points

There's not enough here to replicate the issue. More of the code, properly blockquoted, or better yet a snapshot of your workspace would be very helpful.

But just guessing from what's here now, I wonder if replacing the last line with this might help:

    $studentList.children().eq(i).show();

Happy coding!   -sp:sparkles: