How can I find parent element with display: none using jQuery?
.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>
asked Aug 23, 2018 at 19:26
CMTV
3,1313 gold badges25 silver badges36 bronze badges
1 Answer 1
You need to iterate all parents of .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>
This code also works for elements with style="display: none" attribute.
answered Aug 23, 2018 at 19:26
CMTV
3,1313 gold badges25 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-js