Cheking if div is visible

This question already has an answer here:

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

  • jQuery的选择器可见,所以你可以检查.is(':visible')


    To see if the child div is visible, you can do the following -

    $('#row-1').children().is(':visible')

    !$('#row-1').children().is(':hidden')

    $('#row-1').children().css('display') == 'none'

    But to answer your question, you can do something like this -

    If you want to look for display: inline , you can do the following -

    $('#row-1').children().filter('div[style*=display: inline]').addClass(' myClass ')

    If you want to see if it's visible and then add / remove class, you can do the following -

    $('#row-1').children().filter(':hidden').addClass(' myClass ') // or removeClass


    由于第一个div有一个id,我们可以用它来抓住它的第一个孩子,并检查该孩子的显示值是否等于inline。

    // pure javascript
    
    if (document.getElementById('row-1').firstChild.style.display === 'inline') {
        // add/remove class
    }
    
    链接地址: http://www.djcxy.com/p/2394.html

    上一篇: 如果元素隐藏,做些事情

    下一篇: 检查div是否可见