I have the live demo of the code here: LIVE DEMO
What I am looking to do is when the 1 box is clicked it should scroll to the first section, when the 2 box is clicked it should scroll to the second section and so forth. But when I click on the numbers, I receive the following error:
offset().top is null or not an object
My JQuery looks like:
$(function() {
$(".pointto").mouseover(function() {
$(this).addClass("Hover");
});
$(".pointto").mouseout(function() {
$(this).removeClass("Hover").removeClass("Pressed");
});
$(".pointto").mousedown(function() {
$(this).addClass("Pressed");
});
$(".pointto").mouseup(function() {
$(this).removeClass("Pressed");
});
$(document).on('click', '.Hover, .Pressed, .pointto', function() {
var nn = $(this).attr('id').replace('s', '');
alert('a[name="'+nn+'"]'); //clicking on 1 gives me <a name="01">
t = $('a[name="'+nn+'"]').offset().top; //t = $('a[name="'+nn+'"]').offset().top;
$('body,html').animate({scrollTop:t},800);
});
});
HTML sample:
<a id="s01" class="pointto">1</a> //clickable link
...
...
...
<a name="01">1. About</a> //target
Any idea how to resolve that error?
Update: [RESOLVED]
$(document).on('click', '.Hover, .Pressed, .pointto', function() {
var nn = $(this).attr('id').replace('s', '');
alert('a[name="'+nn+'"]');
t = $('a[name="'+nn+'"]').offset().top; //t = $('a[name="'+nn+'"]').offset().top;
$('body,html').animate({scrollTop:t},800);
});
t = $('a[name="'+nn+'"]')[0].offset().top;?missing ')'error