I am trying to change a hashed URL (document.location.hash) with the replace method, but it doesn\'t work.
$(function(){ var anchor = document.location.hash; /
Either use location or window.location instead of document.location as the latter is a non-standard.
location
window.location
document.location
window.location.hash = '#food';
This will replace the URL's hash with the value you set for it.
Reference