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










37















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?










share|improve this question

















  • 1





    stackoverflow.com/questions/178325/…

    – Johnny Mopp
    Sep 10 '12 at 14:28















37















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?










share|improve this question

















  • 1





    stackoverflow.com/questions/178325/…

    – Johnny Mopp
    Sep 10 '12 at 14:28













37












37








37


8






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?










share|improve this question














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?







jquery






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 10 '12 at 14:25









AristonaAristona

3,23273870




3,23273870







  • 1





    stackoverflow.com/questions/178325/…

    – Johnny Mopp
    Sep 10 '12 at 14:28












  • 1





    stackoverflow.com/questions/178325/…

    – Johnny Mopp
    Sep 10 '12 at 14:28







1




1





stackoverflow.com/questions/178325/…

– Johnny Mopp
Sep 10 '12 at 14:28





stackoverflow.com/questions/178325/…

– Johnny Mopp
Sep 10 '12 at 14:28












7 Answers
7






active

oldest

votes


















49














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.






share|improve this answer

























  • Solved. Thank you.

    – Aristona
    Sep 10 '12 at 14:35











  • One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S

    – bitanath
    Jun 5 '17 at 10:24











  • @bitanath Please check this related question: stackoverflow.com/questions/133051/…

    – undefined
    Jun 6 '17 at 0:12











  • Yeah it makes sense now, thanks @undefined

    – bitanath
    Jun 6 '17 at 6:07



















47
















Check if it's visible.



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



Check if it's hidden.



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






share|improve this answer
































    14














    if element is hide by jquery then use



    if($("#elmentid").is(':hidden'))





    share|improve this answer
































      8














      You can use .css() to get the value of "visibility":



       if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))



      http://api.jquery.com/css/






      share|improve this answer
































        3














        You can use (':hidden') method to find if your div is visible or not..
        Also its a good practice to cache a element if you are using it multiple times in your code..



        $(".subpanel a").click(function() 

        var chatterNickname = $(this).text();
        var $chatPanel = $("#singlechatpanel-1");

        if(!$chatPanel.is(':hidden'))

        alert("Room 1 is filled.");
        $chatPanel.show();
        $("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);

        );





        share|improve this answer






























          3














          if (!$('#singlechatpanel-1').css('display') == 'none') 
          alert('visible');
          else
          alert('hidden');






          share|improve this answer






























            1














            Add your li to a class, and do $(".myclass").hide(); at the start to hide it instead of the visibility style attribute.



            As far as I know, jquery uses the display style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12353741%2fhow-to-check-if-a-div-is-visible-state-or-not%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              49














              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.






              share|improve this answer

























              • Solved. Thank you.

                – Aristona
                Sep 10 '12 at 14:35











              • One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S

                – bitanath
                Jun 5 '17 at 10:24











              • @bitanath Please check this related question: stackoverflow.com/questions/133051/…

                – undefined
                Jun 6 '17 at 0:12











              • Yeah it makes sense now, thanks @undefined

                – bitanath
                Jun 6 '17 at 6:07
















              49














              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.






              share|improve this answer

























              • Solved. Thank you.

                – Aristona
                Sep 10 '12 at 14:35











              • One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S

                – bitanath
                Jun 5 '17 at 10:24











              • @bitanath Please check this related question: stackoverflow.com/questions/133051/…

                – undefined
                Jun 6 '17 at 0:12











              • Yeah it makes sense now, thanks @undefined

                – bitanath
                Jun 6 '17 at 6:07














              49












              49








              49







              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.






              share|improve this answer















              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.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 2 '13 at 5:31

























              answered Sep 10 '12 at 14:30









              undefinedundefined

              125k12133171




              125k12133171












              • Solved. Thank you.

                – Aristona
                Sep 10 '12 at 14:35











              • One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S

                – bitanath
                Jun 5 '17 at 10:24











              • @bitanath Please check this related question: stackoverflow.com/questions/133051/…

                – undefined
                Jun 6 '17 at 0:12











              • Yeah it makes sense now, thanks @undefined

                – bitanath
                Jun 6 '17 at 6:07


















              • Solved. Thank you.

                – Aristona
                Sep 10 '12 at 14:35











              • One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S

                – bitanath
                Jun 5 '17 at 10:24











              • @bitanath Please check this related question: stackoverflow.com/questions/133051/…

                – undefined
                Jun 6 '17 at 0:12











              • Yeah it makes sense now, thanks @undefined

                – bitanath
                Jun 6 '17 at 6:07

















              Solved. Thank you.

              – Aristona
              Sep 10 '12 at 14:35





              Solved. Thank you.

              – Aristona
              Sep 10 '12 at 14:35













              One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S

              – bitanath
              Jun 5 '17 at 10:24





              One question on why we can't just use $('..').css('display') and check for none? CSS newbie here, so not sure :S

              – bitanath
              Jun 5 '17 at 10:24













              @bitanath Please check this related question: stackoverflow.com/questions/133051/…

              – undefined
              Jun 6 '17 at 0:12





              @bitanath Please check this related question: stackoverflow.com/questions/133051/…

              – undefined
              Jun 6 '17 at 0:12













              Yeah it makes sense now, thanks @undefined

              – bitanath
              Jun 6 '17 at 6:07






              Yeah it makes sense now, thanks @undefined

              – bitanath
              Jun 6 '17 at 6:07














              47
















              Check if it's visible.



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



              Check if it's hidden.



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






              share|improve this answer





























                47
















                Check if it's visible.



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



                Check if it's hidden.



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






                share|improve this answer



























                  47












                  47








                  47









                  Check if it's visible.



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



                  Check if it's hidden.



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






                  share|improve this answer

















                  Check if it's visible.



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



                  Check if it's hidden.



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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Oct 27 '14 at 17:25









                  Joshua Pinter

                  25.3k9142172




                  25.3k9142172










                  answered May 29 '14 at 11:14









                  Vipin Kumar R. JaiswarVipin Kumar R. Jaiswar

                  60654




                  60654





















                      14














                      if element is hide by jquery then use



                      if($("#elmentid").is(':hidden'))





                      share|improve this answer





























                        14














                        if element is hide by jquery then use



                        if($("#elmentid").is(':hidden'))





                        share|improve this answer



























                          14












                          14








                          14







                          if element is hide by jquery then use



                          if($("#elmentid").is(':hidden'))





                          share|improve this answer















                          if element is hide by jquery then use



                          if($("#elmentid").is(':hidden'))






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 11 '15 at 9:59









                          NorthCat

                          6,090153239




                          6,090153239










                          answered Mar 11 '15 at 9:37









                          Shah NawazShah Nawaz

                          33129




                          33129





















                              8














                              You can use .css() to get the value of "visibility":



                               if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))



                              http://api.jquery.com/css/






                              share|improve this answer





























                                8














                                You can use .css() to get the value of "visibility":



                                 if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))



                                http://api.jquery.com/css/






                                share|improve this answer



























                                  8












                                  8








                                  8







                                  You can use .css() to get the value of "visibility":



                                   if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))



                                  http://api.jquery.com/css/






                                  share|improve this answer















                                  You can use .css() to get the value of "visibility":



                                   if( ! ( $("#singlechatpanel-1").css('visibility') === "hidden"))



                                  http://api.jquery.com/css/







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Nov 15 '18 at 5:13









                                  Ajay2707

                                  4,36942345




                                  4,36942345










                                  answered Sep 10 '12 at 14:29









                                  Pablo MartinezPablo Martinez

                                  1,9191520




                                  1,9191520





















                                      3














                                      You can use (':hidden') method to find if your div is visible or not..
                                      Also its a good practice to cache a element if you are using it multiple times in your code..



                                      $(".subpanel a").click(function() 

                                      var chatterNickname = $(this).text();
                                      var $chatPanel = $("#singlechatpanel-1");

                                      if(!$chatPanel.is(':hidden'))

                                      alert("Room 1 is filled.");
                                      $chatPanel.show();
                                      $("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);

                                      );





                                      share|improve this answer



























                                        3














                                        You can use (':hidden') method to find if your div is visible or not..
                                        Also its a good practice to cache a element if you are using it multiple times in your code..



                                        $(".subpanel a").click(function() 

                                        var chatterNickname = $(this).text();
                                        var $chatPanel = $("#singlechatpanel-1");

                                        if(!$chatPanel.is(':hidden'))

                                        alert("Room 1 is filled.");
                                        $chatPanel.show();
                                        $("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);

                                        );





                                        share|improve this answer

























                                          3












                                          3








                                          3







                                          You can use (':hidden') method to find if your div is visible or not..
                                          Also its a good practice to cache a element if you are using it multiple times in your code..



                                          $(".subpanel a").click(function() 

                                          var chatterNickname = $(this).text();
                                          var $chatPanel = $("#singlechatpanel-1");

                                          if(!$chatPanel.is(':hidden'))

                                          alert("Room 1 is filled.");
                                          $chatPanel.show();
                                          $("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);

                                          );





                                          share|improve this answer













                                          You can use (':hidden') method to find if your div is visible or not..
                                          Also its a good practice to cache a element if you are using it multiple times in your code..



                                          $(".subpanel a").click(function() 

                                          var chatterNickname = $(this).text();
                                          var $chatPanel = $("#singlechatpanel-1");

                                          if(!$chatPanel.is(':hidden'))

                                          alert("Room 1 is filled.");
                                          $chatPanel.show();
                                          $("#singlechatpanel-1 #chatter_nickname").html("Chatting with: " + chatterNickname);

                                          );






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Sep 10 '12 at 15:20









                                          Sushanth --Sushanth --

                                          50.6k64885




                                          50.6k64885





















                                              3














                                              if (!$('#singlechatpanel-1').css('display') == 'none') 
                                              alert('visible');
                                              else
                                              alert('hidden');






                                              share|improve this answer



























                                                3














                                                if (!$('#singlechatpanel-1').css('display') == 'none') 
                                                alert('visible');
                                                else
                                                alert('hidden');






                                                share|improve this answer

























                                                  3












                                                  3








                                                  3







                                                  if (!$('#singlechatpanel-1').css('display') == 'none') 
                                                  alert('visible');
                                                  else
                                                  alert('hidden');






                                                  share|improve this answer













                                                  if (!$('#singlechatpanel-1').css('display') == 'none') 
                                                  alert('visible');
                                                  else
                                                  alert('hidden');







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Sep 1 '15 at 9:55









                                                  PrabhagaranPrabhagaran

                                                  2,3411217




                                                  2,3411217





















                                                      1














                                                      Add your li to a class, and do $(".myclass").hide(); at the start to hide it instead of the visibility style attribute.



                                                      As far as I know, jquery uses the display style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)






                                                      share|improve this answer



























                                                        1














                                                        Add your li to a class, and do $(".myclass").hide(); at the start to hide it instead of the visibility style attribute.



                                                        As far as I know, jquery uses the display style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)






                                                        share|improve this answer

























                                                          1












                                                          1








                                                          1







                                                          Add your li to a class, and do $(".myclass").hide(); at the start to hide it instead of the visibility style attribute.



                                                          As far as I know, jquery uses the display style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)






                                                          share|improve this answer













                                                          Add your li to a class, and do $(".myclass").hide(); at the start to hide it instead of the visibility style attribute.



                                                          As far as I know, jquery uses the display style attribute to show/hide elements instead of visibility (may be wrong on that one, in either case the above is worth trying)







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Sep 10 '12 at 14:33









                                                          PhonicUKPhonicUK

                                                          10.4k22854




                                                          10.4k22854



























                                                              draft saved

                                                              draft discarded
















































                                                              Thanks for contributing an answer to Stack Overflow!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid


                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.

                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function ()
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12353741%2fhow-to-check-if-a-div-is-visible-state-or-not%23new-answer', 'question_page');

                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Use pre created SQLite database for Android project in kotlin

                                                              Darth Vader #20

                                                              Ondo