我使用的是Popcorn.js,它创建了以下HTML代码:
<div id="row-1">
<div style="display: none;">Hello</div>
</div>但是现在,当.myClass中的div是display: inline时,我尝试使用jQuery向#row1添加/删除#row1。
我尝试过.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>发布于 2014-12-23 19:08:07
jQuery有选择器可见,所以您可以检查.is(':visible')
发布于 2014-12-23 19:27:34
要查看子div是否可见,可以执行以下操作-
$('#row-1').children().is(':visible') !$(‘#row-1’).children().is(‘:隐藏’) $(‘#行-1’).children().css(‘display’) == 'none‘
但要回答你的问题,你可以这样做-
如果你想找display: inline,你可以做以下-
$('#row-1').children().filter('divstyle*=display: inline').addClass('myClass')
如果您希望查看它是否可见,然后添加/删除类,则可以执行以下操作-
$('#row-1').children().filter(':hidden').addClass('myClass') //或removeClass
发布于 2014-12-23 19:11:47
因为第一个div有一个id,所以我们可以使用它来获取它的第一个子节点,并检查该子元素的显示值是否等于内联。
// pure javascript
if (document.getElementById('row-1').firstChild.style.display === 'inline') {
// add/remove class
}https://stackoverflow.com/questions/27626483
复制相似问题