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!
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!
Share Improve this question edited Jan 13, 2011 at 23:41 BoltClock 724k165 gold badges1.4k silver badges1.4k bronze badges asked Jan 13, 2011 at 23:38 ThomasThomas 1,0794 gold badges18 silver badges40 bronze badges 3 |1 Answer
Reset to default 22Compare 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);
}
window.location.hash
givenull
? Maybe you should check for that first in someJS API
. I think it will give you an empty string. – Marnix Commented Jan 13, 2011 at 23:42