I have tabs like this.
<li id="singlechatpanel-1" style="visibility: hidden;"> //content </li>
Trying to check it like this:
$(".subpanel a").click(function() { var chatterNickname = $(this).text(); if(!$("#singlechatpanel-1").is(':visible')) { alert("Room 1 is filled."); $("#singlechatpanel-1").css({'visibility':'visible'}); $("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname); }
If condition always returns false. How can I check visibility state of this div?
Solution 1. Make sure you're div has an id and a runat="server" on it and then you can access it in codebehind.
Summary. Use the getBoundingClientRect() method to get the size of the element and its relative position to the viewport. Compare the position of the element with the viewport height and width to check if the element is visible in the viewport or not.
is visible in DOM? visibility of the objects. Method 2: Using getComputedStyle() mETHOD: The getComputedStyle() method is used to return an object that contains all the CSS properties of the element. Each of these properties can now be checked for any property required.
display = 'inline'; to make the div display inline with other elements. And we can write: const div = document.
$("#singlechatpanel-1").is(':visible');
$("#singlechatpanel-1").is(':hidden');
is(':visible')
checks the display
property of an element, you can use css
method.
if (!$("#singlechatpanel-1").css('visibility') === 'hidden') { // ... }
If you set the display
property of the element to none
then your if
statement returns true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With