Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a div is visible state or not?

Tags:

jquery

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?

like image 832
Aristona Avatar asked Sep 10 '12 14:09

Aristona


People also ask

How check div is visible or not in C#?

Solution 1. Make sure you're div has an id and a runat="server" on it and then you can access it in codebehind.

How do I know if my element is visible on screen?

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.

How do you know if an element is visible in Dom?

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.

How do I make a div visible?

display = 'inline'; to make the div display inline with other elements. And we can write: const div = document.


2 Answers

Check if it's visible.

$("#singlechatpanel-1").is(':visible');

Check if it's hidden.

$("#singlechatpanel-1").is(':hidden');

like image 61
Vipin Kumar R. Jaiswar Avatar answered Oct 19 '22 20:10

Vipin Kumar R. Jaiswar


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.

like image 28
undefined Avatar answered Oct 19 '22 19:10

undefined