I can’t get $(target) to work.
If I click on a link with href=#top, alert(target) displays #top, but $(target).offset returns null.
$("[href^='#']").click( function() {
var target = $(this).attr('href');
alert(target);
$("#body-wrapper").animate( {scrollTop: $(target).offset().top} ,300);
return false
})
};
When you do:
You’re essentially doing:
But, you apparently don’t have an object in your page with an ID of “top” (thus why it returns null). So, this could work if you gave the link with the name of top that ID also like this:
Or, instead, you could use this jQuery to look for the link tag with name=”top”:
Here you look for a tag with an attribute of name=’top’.