2014-12-23 33 views
5

我使用Popcorn.js并创建下面的HTML代码:Cheking如果DIV可见

<div id="row-1"> 
    <div style="display: none;">Hello</div> 
</div> 

但现在我想添加/使用jQuery删除.myClass.test时,里面的DIV #row1display: inline

我试过.height().lenght().width()(但这个不起作用,因为div的宽度是始终1246px

任何帮助将不胜感激!


** 编辑 **

整个HTML代码:

<html> 
    <head> 
    <script src="http://popcornjs.org/code/dist/popcorn-complete.min.js"></script> 

    <script src="js/jquery-1.11.2.min.js"></script> 

     <style> 
     .myClass{ 
      background: yellow !important; 
     } 
     </style> 

    <script> 
     // ensure the web page (DOM) has loaded 
     document.addEventListener("DOMContentLoaded", function() { 

      // Create a popcorn instance by calling the Youtube player plugin 
     var example = Popcorn.youtube(
      '#video', 
      'https://www.youtube.com/embed/w9l4v1s9148?controls=1'); 

     example.footnote({ 
      start: 1.2, 
      end: 1.7, 
      text: "Hello", 
      target: "row-1" 
     }); 

     example.footnote({ 
      start: 1.7, 
      end: 3.2, 
      text: "boys and girls", 
      target: "a2" 
     }); 

     example.footnote({ 
      start: 3.2, 
      end: 4.8, 
      text: "my name is FatLip,", 
      target: "a3" 
     }); 

     example.footnote({ 
      start: 4.8, 
      end: 7, 
      text: "and this is my friend, Simon the Salmon.", 
      target: "a4" 
     }); 


     }, false); 
    </script> 
</head> 

<body> 
    <div id="video" style="width: 360px; height: 300px;" ></div> 

    <div id="row-1"></div> 
    <div id="a2"></div> 
    <div id="a3"></div> 
    <div id="a4"></div> 

    <div class="test" style="width: 10px; height: 10px; background: black;"></div> 
</body> 
</html> 
+0

用'$(EL)试试。就是(“:visible”)' – juvian

回答

11

jQuery有选择visible使您可以检查.is(':visible')

2

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

// pure javascript 

if (document.getElementById('row-1').firstChild.style.display === 'inline') { 
    // add/remove class 
} 
+0

看起来像这是正确的答案,但您可能想扩大一点,以解释为什么这可以解决问题 – brandonscript

3

要看看孩子的div是可见的,你可以做以下 -

$( '#行1')儿童()是( ':可见')

$( '#行1')儿童()是!( ':隐藏')。

$( '#行1')儿童()的CSS( '显示')= ='无'

但是,为了回答你的问题,你可以做这样的事情 -

如果您想寻找display: inline,你可以做以下 -

$(“#行1”)儿童( ).filter( 'DIV [风格* =显示:内联')addClass( 'MyClass的')

如果你想看看它的可见光,然后添加/删除类,你可以做的。以下 -

$( '#行1')儿童()过滤器( ':隐藏')。addClass( 'MyClass的')//或者removeClass

+0

'none'不是一个声明变量 –

+0

对不起。没有注意到 –