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

前端 未结 7 1999
不知归路
不知归路 2020-12-24 12:11

I have tabs like this.

  • //content
  • Trying to check it like

    相关标签:
    7条回答
    • 2020-12-24 12:42

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

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

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

      0 讨论(0)
    • 2020-12-24 12:43

      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);
              }
      });
      
      0 讨论(0)
    • 2020-12-24 12:44

      if element is hide by jquery then use

      if($("#elmentid").is(':hidden'))
      
      0 讨论(0)
    • 2020-12-24 12:50

      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)

      0 讨论(0)
    • 2020-12-24 12:57
      if (!$('#singlechatpanel-1').css('display') == 'none') {
         alert('visible');
      }else{
         alert('hidden');
      }
      
      0 讨论(0)
    • 2020-12-24 12:59

      Check if it's visible.

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

      Check if it's hidden.

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

      0 讨论(0)
    提交回复
    热议问题