I use those rows to show hide some elements:
function isActive()
{
$("#id1").hide();
$("#id2").show();
}
But I need to change the rows above to make elements dispayed or hide according to bool value:
function isActive(toShow)
{
$("#id1").hide();
$("#id2").show();
}
what is the best way to implemnt it?
Use $.fn.toggle(Boolean: display):
function isActive(toShow)
{
$("#id1").toggle(!toShow); // Hide when toShow = true, show when toShow = false
$("#id2").toggle(!!toShow); // Hide when toShow = false, show when toShow = true
}
It is however important to make sure toShow is a boolean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With