JQuery: if div is visible

This question already has an answer here:

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

  • You can use .is(':visible')

    Selects all elements that are visible.

    For example:

    if($('#selectDiv').is(':visible')){
    

    Also, you can get the div which is visible by:

    $('div:visible').callYourFunction();
    

    Live example:

    console.log($('#selectDiv').is(':visible'));
    console.log($('#visibleDiv').is(':visible'));
    #selectDiv {
      display: none;  
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="selectDiv"></div>
    <div id="visibleDiv"></div>
    链接地址: http://www.djcxy.com/p/2390.html

    上一篇: 检查元素的可见性

    下一篇: JQuery:如果div可见