JQuery UI - swap feature that hides and hides elements using a selector
Foreword: I have jQuery and jQuery UI included in a page.
I have this function defined:
function swap(sel) {
if (1 == 1) {
$(sel).hide('drop',{direction:'left'});
}
}
How do I fix the (1 == 1) part to check if the element is hidden and then return it if it is. I'm sure it's easy, but I'm new to jQuery.
0
source to share
4 answers
As other respondents said, toggle()
is the best solution. However, if for some reason you can't / don't want to use a switch, and if your selector is only for one element:
function swap(sel) {
if ($(sel).is(':visible')) { // Is this element visible?
$(sel).hide('drop',{direction:'left'});
}
}
Caution: . The visible check will return a false positive value if the item or any of its parents :hidden
. If this is important to you, you might want to check this solution , which also tries to test it.
+2
source to share