Reputation: 12414
I have code that uses jquery.slideup and jquery.slidedown
How can i know that div is hidden?
Upvotes: 34
Views: 72433
Reputation: 1891
HTML CODE:
when you click on div id "collapse" if the the div id "flex-container" is visible then its hide and if hide then visible.
<div id="collapse" >collapse</div>
JQUERY CODE:
$(document).ready(function() {
$("#collapse").on('click', function() {
if($('#flex-container').is(':visible'))
{ $("#flex-container").hide(); }
else
{ $("#flex-container").show(); }
});
});
Upvotes: 0
Reputation: 7956
$('#id').is(':hidden'); //true if is hidden
$('#id').is(':visible'); //true if is visible
But you may want to use slideToggle for your needs.
Upvotes: 23
You could use $("#elementID").height() == 0 since you know it is either going to be up or down. It may be faster than doing the .is(":visible") as well but I haven't done any testing on that fact.
Upvotes: 0
Reputation: 828190
To see if an element is visible or not, you can use the visible selector with the is function:
$("#idElement").is(":visible") // true or false
But sounds to me like you want to toggle the slide effect, for that you can use the slideToggle function.
Upvotes: 95
Reputation: 5475
You can use the visible selector:
http://docs.jquery.com/Selectors/visible
Upvotes: 2