I am using a script to add a hash tag to the URL of the page. (I know I could just type the link as url.com/page.html#align-page but for users who come to the page without the hash tag I add it dynamically to direct them to the spot I want.)
I can see the hash tag added in the page URL but it sometimes goes to the correct div and other times it doesn’t.
Why does this not work 100% of the time?
Here is the script (this script is in the <head>)
var $j = jQuery.noConflict();
$j(document).ready(function(){
window.location.hash = "align-page";
});
Note: The script is contained within the $j(document).ready(function(){ as there are other scripts that are not listed here that are also within the { }. If it needs to be placed outside of the { } I can move it.
Also if there is a better way to do this with jQuery or another method I would welcome that.
Try this instead: