Jquery hash if no hash

Trying to get #home to display if there is no hash in the URL. I realized that something in these lines would work quite easily, but I can't do anything:

if(window.location.hash != null){ $(window.location.hash).fadeIn(800); } else { $('#home').fadeIn(800); } 

I have never worked with if / else statements in jquery, so this is clearly wrong

thanks!

+6
javascript jquery hash
source share
1 answer

Compare it with an empty string instead (zero and empty string are not equal in JavaScript):

 if(window.location.hash != ''){ $(window.location.hash).fadeIn(800); } else { $('#home').fadeIn(800); } 
+19
source share

All Articles