In jQuery (I'm currently using 1.11.4), is there any inbuilt helper function to allow you to show/hide elements based on a variable?
For instance, at the moment to show/hide something based on a checkbox I do something like these two examples...
$("#myChk").on("click", function() {
if ($(this).is(":checked")) {
$("#otherEl").show();
} else {
$("#otherEl").hide();
}
});
$("#myChk").on("click", function() {
var $otherEl = $("#otherEl");
($(this).is(":checked") ? $otherEl.show() : $otherEl.hide());
});
Is there a single inbuilt function that I can't easily find in the documentation that allows something like...
$("#myChk").on("click", function() {
$("#otherEl").showOrHide($(this).is(":checked"))
});
I'm pretty sure there isn't anything, but I thought I'd ask just in case.
I'm aware of .toggle()
but that is based on the current visibility of the element, not an external variable.
(And if anybody is aware of anything similar for .slideUp
and .slideDown
that would also be useful.)