I need to make back and forward buttons working with this ajax method
This code working good and the URL on browser changing as it should be
but when you click on back and forward buttons, nothing happening
(function(){
function clickNav(e){
e.preventDefault();
var href = $(this).attr('href');
history.pushState(null, null, href);
$.ajax({
url: href,
dataType: 'html',
cache: false
}).done(function(html){
var $html = $(html);
$('title').html($html.filter('title').text());
$('#content').replaceWith($html.find('#content'));
$('#nav').replaceWith($html.find('#nav'));
$('#nav li a').on('click',clickNav);
});
}
$('#nav li a').on('click',clickNav);
})();