如何使用jQuery使用display: none
查找父元素?
.hidden-one
{
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hidden-one"> <!-- FIND AND SHOW THIS ONE -->
<div>...</div>
<div>...</div>
<div class="deeper">
<span class="start-here">Start here</span>
</div>
<div>...</div>
</div>
答案 0 :(得分:1)
您需要迭代.start-here
的所有父母:
$('.start-here').parents().each(function() {
if ($(this).css('display') === 'none')
{
$(this).show();
}
});
.hidden-one
{
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hidden-one"> <!-- FIND AND SHOW THIS ONE -->
<div>...</div>
<div>...</div>
<div class="deeper">
<span class="start-here">Start here</span>
</div>
<div>...</div>
</div>
此代码也适用于具有style="display: none"
属性的元素。