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

2 replies
HelloFriends 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.

$(document).ready(function($){
$('a[href^="#"]').bind('click.smoothscroll',function (e) {
e.preventDefault();

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

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

});
#fix #null #property #read #top #typeerror #uncaught
  • Profile picture of the author Bruce Hearder
    I guess from this error, that $target is not defined.. Might need to do some console debugging and see what it comes back with.

    Hope this helps

    bruce

    Originally Posted by Marshall23 View Post

    HelloFriends 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.

    $(document).ready(function($){
    $('a[href^="#"]').bind('click.smoothscroll',function (e) {
    e.preventDefault();

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

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

    });
    {{ DiscussionBoard.errors[7737943].message }}
  • Profile picture of the author Michael71
    Give me the URL please.
    Signature

    HTML/CSS/jQuery/ZURB Foundation/Twitter Bootstrap/Wordpress/Frontend Performance Optimizing
    ---
    Need HTML/CSS help? Skype: microcosmic - Test Your Responsive Design - InternetCookies.eu

    {{ DiscussionBoard.errors[7738183].message }}

Trending Topics