How I can I make jQuery go directly to <h2 id="id-name">?
You can set location.hash
to the id
you need the browser to scroll to:
window.location.hash = '#edit';
In my experience the window.location.hash
solution only works once. If you don't want to use the plugin you could try this:
var navigationFn = {
goToSection: function(id) {
$('html, body').animate({
scrollTop: $(id).offset().top
}, 0);
}
}
and then call it like so (where someID
is the ID of the element you wish to scroll to):
navigationFn.goToSection('#someID');
With this you can also vary the animation speed (I have it at 0) so that it is instant, but you could pass the value to the function so the code is reusable.