Matt Elhotiby
Matt Elhotiby

Reputation: 44066

how do i display the first hidden div with a specific class with jQuery?

So i have this situation ....

<div class="nested_fields"></div>
<div class="nested_fields" style="display: none;"></div>
<div class="nested_fields"></div>
<div class="nested_fields"></div>
<div class="nested_fields" style="display: none;"></div>
<div class="nested_fields" style="display: none;"></div>
<div class="nested_fields" style="display: none;"></div>

I want to display show the first nested_fields div that is not hidden...so in the above situation it would be the second div with Jquery

Upvotes: 0

Views: 842

Answers (2)

Matt Elhotiby
Matt Elhotiby

Reputation: 44066

try this

$('.nested_fields:hidden:first')

Upvotes: 1

fmsf
fmsf

Reputation: 37147

$(".nested_fields:hidden").first().show();

or as $(".nested_fields") returns an array of objects you can also do:

$(".nested_fields:hidden")[0].show();

or using only selectors:

 $(".nested_fields:hidden:first").show();

Upvotes: 1

Related Questions