开发者

jquery hash if no hash

开发者 https://www.devze.com 2023-02-04 08:30 出处:网络
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:

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(开发者_JAVA技巧800);
   }

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

thanks!


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消