views:

64

answers:

1
var a=asdf;
var b=asdfs;
//var a = new String("asdf");
    if (a.equals(b)) {
        $("#package").show();
    }
    else {
          $("#package").hide();
    }

});
+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
you can even use slideToggle() if you want to animate it! :)
jimplode
@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
+1 for the tripple equals :-0
James Wiseman
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
@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
Nick: yes, no criticism intended.
Tim Down
@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