I would like to show and hide objects (divs, texts or btns) according to some conditions.
In C #, we can write to reduce the number of encodings:
txtA.visible = (type == "A");
txtB.visible = (type == "B");
txtC.visible = (type == "C");
In jQuery, to show and hide, I use the .show () and .hide () methods. But I have to write a lot of lines for this simple function. For instance,
if (type == "A")
$("#txtA").show();
else
$("#txtA").hide();
if (type == "B")
$("#txtB").show();
else
$("#txtB").hide();
if (type == "C")
$("#txtC").show();
else
$("#txtC").hide();
In any case, to achieve the same functionality with fewer lines? Thank.
source
share