var a=asdf;
var b=asdfs;
//var a = new String("asdf");
if (a.equals(b)) {
$("#package").show();
}
else {
$("#package").hide();
}
});
views:
64answers:
1
+6
A:
You need quotes around your strings, and there is no .equals() method in JavaScript, overall:
var a="asdf";
var b="asdfs";
if (a === b) {
$("#package").show();
}
else {
$("#package").hide();
}
Or, since there's a .toggle(bool) shortcut, more simply:
$("#package").toggle(a===b);
Nick Craver
2010-09-24 11:35:57
you can even use slideToggle() if you want to animate it! :)
jimplode
2010-09-24 11:41:41
@jimplode - something to keep in mind is `.slideToggle()` *doesn't* have a boolean overload, though you could make one easily enough it's not as straightforward since an animation may be in progress.
Nick Craver
2010-09-24 11:43:10
+1 for the tripple equals :-0
James Wiseman
2010-09-24 11:57:20
If `a` and `b` are both strings then there's no need to use `===`, so it seems a little generous to award a +1 solely on that basis.
Tim Down
2010-09-24 13:11:01
@Tim - It's unclear from the question if that's always the case, it could be `var a=0, b="0"` as well, better to be safe IMO.
Nick Craver
2010-09-24 20:57:33
Nick: yes, no criticism intended.
Tim Down
2010-09-24 23:04:19
@Tim - oh I know :) that was much more for others reading this, sorry I don't make that clear most of the time...above all I consider questions/answer/comments as a google resource, even before they're actually responses :)
Nick Craver
2010-09-24 23:05:52