Question: I was just wondering if it was possible to do something like this in jQuery:

```
$('#MyDiv').show((MyVar==2?1:0)); // 1=show, 0=hide.

```

otherwise I'd have to write it like this everywhere.

```
if(MyVar==2?1:0){$('#MyVar').show();}else{$('#MyVar').hide();}

```

Answer: 
There's a built-in function [`.toggle(boolean value)`](http://api.jquery.com/toggle/#toggle-showOrHide) since jQuery 1.3:

```
$('#MyDiv').toggle(MyVar === 2);

```
Considering that the manual for .show() says it takes no arguments, I believe that you must do it the 2nd way.

I would recommend instead something like `if (MyVal==2) { $('#MyVar').show(); } else { $('#MyVar').hide(); }`. The ? operator is unnecessary in an if since MyVal==2 already evaluates to a true (1) or false (0). Also, putting spaces in your code will drastically improve your readability and you will thank yourself later when trying to debug things.

Edit: lol forgot about the toggle method...that works too.