Determine whether the div is opened or closed using jquery?
I am want 开发者_如何转开发to create a javascript function using jQuery which will close the div if div is opened and vice-versa.
For that I need to determine whether a particular div is opened or closed?
So is there any method available which satisfies my requirement?
Anything like $('div#myContainer').isOpened() ???
do you mean like this?
if($('#myContainer').is(':visible')){
$('#myContainer').slideToggle();
}
Or
$('#clickme').click(function() {
$('#myContainer').slideToggle('slow', function() {
//Do something
});
});
You could set a custom attribute to the div that you could check with jQuery and use as a flag. You can also look at the toggle() method
What do you mean by "opened"?
Would something like this do?
$('#myContainer').is(':visible')
Check if Div's css "Display" property is none You can get css attribute by
var checkOpen =$('#myContainer').css('display');
精彩评论