0

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.