Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery hash if no hash

Trying to get #home to display if there is no hash present in the url. I figured something along these lines would work pretty easy but I can't get anything going:

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

I've never worked with if / else statements in jquery, so this is obviously wrong

thanks!

like image 215
Thomas Avatar asked Jan 13 '11 23:01

Thomas


1 Answers

Compare it against the empty string instead (null and the empty string aren't equal in JavaScript):

if(window.location.hash != ''){ 
   $(window.location.hash).fadeIn(800);
} else {
   $('#home').fadeIn(800);
}
like image 195
BoltClock Avatar answered Oct 11 '22 01:10

BoltClock