hash = hash.replace( /^#/, '' );
var node = $( '#' + hash );
if ( node.length ) {
node.attr( 'id', '' );
}
document.location.hash = hash;
if ( node.length ) {
node.attr( 'id', hash );
}
Im having trouble with the code above, which I grabbed from this article: Modifying document.location.hash without page scrolling, trying to temporarily replace the id of a div while I change the location.hash to said id. hash comes up with this error in the console: Uncaught ReferenceError: hash is not defined. I’m new to JS and need a little guidance! thanks 🙂
The first line seems wrong:
Are you sure you defined the hash variable before it?
I think it has to be like this:
and then the rest of code shouldn’t cause the error