When Jquery uses toggle(), how to judge the state

Q: How does the toggle method know whether it is show or hide now, and there is no return value true or false. How to get it, because I just want to judge whether the current is show or hide and need to execute some code, experts answer! Answer: If there is such an element: <div id=”mDiv” style=”display:none”>DIV1</div> to judge whether it is displayed or not, the is() method can be used, specifically, if($( “#mDiv”).is(“:hidden”)){ $(this).show(); }else{ $(this).hide(); }

answer

Look directly at the code:

1
2
3
4
5
6
7
// 请确保不要使用太低版本的 jQuery
var select = $( '#id' );
if ( select.toggle().is( ':hidden' ) ) {
    alert(

The post Jquery How to tell the status when using toggle() first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9669
This site is for inclusion only, and the copyright belongs to the original author.