JQuery Check to See if Div is Shown

This question already has an answer here:

  • How do I check if an element is hidden in jQuery? 53 answers

  • if ( $(this).is(':visible') )应该适用于这个相对简单的显示/隐藏。


    Sometime need to check that div is block or none. We can do this very easily . This is simple code . here id = "test" -> for testing purpose if you use class = "test" then need to update code For checking Block or visible then use this for your select test is id

    1. if ($('#test').is(':visible')) {}
    
    2. if ($('#test').css('display') == 'block'){}
    
    3. if ($('#test').not(':hidden')){}
    

    if your selector is class then

    1. if ($('.test').is(':visible')) {}
    

    or

    1. if ($(your_element).is(':visible')) {}
    

    same other

    For checking none or hide then use this code if your selector is id

    1. if ($('#test').not(':visible')){}
    
    2. if (!$('#test').is(':visible')){}
    
    3. if ($('#test').css('display') == 'none'){}
    
    4. if ($('#test').is(':hidden')){}
    

    if your selector is class then use this

    1. if ($('.test').not(':visible')){}
    

    or

    1. if ($(your_element).not(':visible')){}
    

    hope it will help you


    You can try this:

    $(your_element).is(":visible") 
    

    Example;

    if ($('#element_id').is(":visible") ) {
        // do something
    }
    
    链接地址: http://www.djcxy.com/p/14570.html

    上一篇: 检查元素在DOM中是否可见

    下一篇: JQuery检查以查看是否显示Div