Check div is hidden using jquery

前端 未结 6 1080
故里飘歌
故里飘歌 2021-02-01 14:46

This is my div

Then I have a Show button that will show the div when you click:

相关标签:
6条回答
  • 2021-02-01 15:05

    Try checking for the :visible property instead.

    if($('#car2').not(':visible'))
    {
        alert('car 2 is hidden');       
    }
    
    0 讨论(0)
  • 2021-02-01 15:20

    You can use,

    if (!$("#car-2").is(':visible'))
    {
          alert('car 2 is hidden');
    }
    
    0 讨论(0)
  • 2021-02-01 15:21

    Try

    if($('#car2').is(':hidden'))
    {  
        alert('car 2 is hidden');       
    }
    
    0 讨论(0)
  • 2021-02-01 15:22

    You can check the CSS display property:

    if ($('#car').css('display') == 'none') {
        alert('Car 2 is hidden');
    }
    

    Here is a demo: http://jsfiddle.net/YjP4K/

    0 讨论(0)
  • 2021-02-01 15:23

    Did you notice your typo, $car2 instead of #car2 ?

    Anyway, :hidden seems to be working as expected, try it here.

    0 讨论(0)
  • 2021-02-01 15:29

    Try:

    if(!$('#car2').is(':visible'))
    {  
        alert('car 2 is hidden');       
    }
    
    0 讨论(0)
提交回复
热议问题