JQuery .is( ":visible" ) always returning TRUE
I can't seem to get the .is( ":visible" ) to work. It always returns true. I believe I have followed the correct syntax, etc. Clicking on .heading, toggles the .details class to hide/show. All seems to work fine, except the .is(";visible") always returns true, even when the .details gets hidden and I can clearly see the display:none is there. Maybe something to do with the fact the display property is dynamically changed...?
Code is below:
- <html>
- <head>
- <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous" type="text/javascript" charset="utf-8"></script>
- </head>
- <body>
- <br><br>
- <div id="question_section315">
- <p class="details" id="top_header315" style="margin-top: -10px;">TEST TEXT</p>
- <p class="details">OTHER TEST TEXT #2</p>
- <div class="row">
- <h1 class="heading" data-id="315" style="display:inline-block;white-space:pre-wrap;cursor:pointer;">TEST HEADER</h1>
- </div>
- </div>
- <script>
- $(document).on("click", ".heading", function(){
- var id = $(this).attr("data-id");
- $('#question_section'+id).find('.details').toggle(500);
- console.log('#top_header'+id);
- var visible = $('#top_header'+id).is( ":visible" );
- console.log('visible: '+visible);
- //other logic if visible here
- });
- </script>
- </body>
- </html>