I'm just wondering if something like this can be done in jQuery:
$('#MyDiv').show((MyVar==2?1:0)); // 1=show, 0=hide.
otherwise I would have to write it like this everywhere.
if(MyVar==2?1:0){$('#MyVar').show();}else{$('#MyVar').hide();}
There is a built-in function .toggle(boolean value)since jQuery 1.3:
.toggle(boolean value)
$('#MyDiv').toggle(MyVar === 2);
Given that the manual for .show () says that it takes no arguments, I believe that you should do this in the 2nd way.
- if (MyVal==2) { $('#MyVar').show(); } else { $('#MyVar').hide(); }.? , myVal == 2 true (1) false (0). , , , .
if (MyVal==2) { $('#MyVar').show(); } else { $('#MyVar').hide(); }
: lol ... .