I'm trying to make a page scroll
when I click on a link from my navbar, but when I click I get the following error in the console:
Uncaught TypeError: Can not read property 'top' of undefined
$(document).ready(function (){
setBindings();
});
function setBindings() {
$("nav a").click(function(e) {
e.preventDefault();
var sectionID = e.currentTarget.id;
$('html, body').animate({
scrollTop: $("#" + sectionID).offset().top
}, 2000);
});
}
I do not understand, I am a layperson with javascript
the code was from a video that I saw on Youtube .