How to hide the next button after getting all the pages ?

How to hide the next button after getting all the pages ?

Hi,how to hide the next button if page is last page then not need to show next as this is last page.can anyone help me.

My code :

// Next page 
$('.next').on('click', function () {
var next = '#' + $.mobile.activePage.next('[data-role=page]')[0].id;
$.mobile.changePage(next, {
transition: 'slide'
});
});