I have written a js scripts to point an id on document.ready function but when I used same other id in the url then it pointed to the previous id, My first point id is abc.com/#firstid and second is id abc.com/#secondid. while I am using it second id in the same browser same tab it pointed to first is i.e pointing to the section having id #firstid
jQuery( document ).ready(function(e) {
if (window.location.href.indexOf("/#") > -1) {
var str = window.location.href;
var spilt = str.split("/#");
var url_id = spilt[1];
console.log(url_id);
jQuery('html, body').animate({ scrollTop: jQuery("."+url_id).offset().top-100 }, 100);
}
});
<div class="#firstid">
1
</div>
<div class="#secondid">
2
</div>
after browse the url in browser abc.com/#firstid it points on 1 and while browse abc.com/#secondid it pointed on 2 but after then goes to 1 as page complete load