I have searched on StackOverflow but no questions matched my specific dilemma. I have a div with a class foo that is set via css to display: inline-block.
I would like foo to be visible when the variable temp is a number or a string, but not display when it is not a number or a string.
var temp;
if (temp != undefined || temp != null) {
temp = temp / 1000;
temp = temp + 'K';
$('.foo').css("display", "inline-block");
}
else {
$('.foo').css("display", "none");
}
When I run this code the "foo" does not display at all.
when I change the code to
var temp;
if (temp != undefined || temp != null) {
temp = temp / 1000;
temp = temp + 'K';
$('.foo').css("display", "inline-block");
}
if (temp == undefined || temp == NaN) {
$('.foo').css("display", "none");
}
foo is still all set to display:"none"
I ran console.log on each if, and when temp is a value it does go through the first if and when it is NaN or null it does go through the second if. But why does ONLY the display: "none" take affect?
Thank you in advance. - VS
Aucun commentaire:
Enregistrer un commentaire