I'm doing a page which when clicking on an option on the menu, it goes to an anchor of it. There's even good. When I use the following code in jquery for scrolling
$('nav a').click(function(e){
e.preventDefault(); //evitar el eventos del enlace normal
enlace = $(this).attr('href');
$('html, body').animate({
scrollTop: $(enlace).offset().top
}, 1000);
});
The following message appears on the console
Uncaught TypeError: Can not read property 'top' of undefined
In the examples I find online I see that they use it but it does not work for me.