How to fix uncaught typeError: cannot read property 'top' of null?

Hello forum members i have a jquery problem. whenever i tried to apply on click scroll script i got this error “uncaught typeError: cannot read property ‘top’ of null”. Here following is code of Jquery.How can this will be fixed.

$(‘a[href^=“#”]’).bind(‘click.smoothscroll’,function (e) {

var target = this.hash,
$target = $(target);

$(‘html, body’).stop().animate({
‘scrollTop’: $target.offset().top
}, 900, ‘swing’, function () {
window.location.hash = target;


I created a demo using your above code and it worked fine so I would suggest you ensure all your anchor hash tags match up to real element id’s in your markup as that it what will be causing the error, additionally you should always have some kind of error checking to ensure the hash matches up to something.