Reputation: 15016
I tried the following:
console.log(location.hash)
if(location.hash = ''){
console.log('home')
}
What conditional should I set to get the console to log home on for example example.com/
Upvotes: 0
Views: 50
Reputation: 167182
The location.hash
will not be set:
if (location.hash == null)
if (!location.hash)
And in your code, you are assigning! Not comparing! Use ==
!
Upvotes: 0
Reputation: 214
The following will log home on example.com/
if(window.location.pathname == '/'){
console.log('home')
}
You need to use the pathname property, not hash.
Upvotes: 1
Reputation: 608
Are you looking to test if a hash exists?
// If there is no hash
if(!window.location.hash){
console.log("no hash");
}
Upvotes: 0