I have this html codes:
<span name="value1"></span>
<span name="value2"></span>
I'm trying to make the page scroll to these sections every time the page's URL with the span loads.
Example: htttp://site.com/index.html#value1
If value1
is selected, there is a scroll when the page is opened.
I'm trying this code :
$(document).ready(function() {
var target = $(this.hash);
if (target.length == 0) target = $('[name="' + this.hash.substr(1) + '"]');
if (target.length == 0) target = $('html');
$('html, body').animate({ scrollTop: target.offset().top }, 700);
return false;
});
I can do this with id
but I want to do it with name attr.