I am struggling with a DIV structure that looks like this:
<div class="metafield_table">
<div class="metafield"></div>
<div class="metafield"></div>
<div class="metafield"></div>
</div>
The number of metafield
elements can vary, and I specifically need to determine if the Second Child exists.
How can I achieve this using jQuery?
This is what I attempted:
var secondChild = $('.metafield_table .metafield:nth-child(2)').val;
if(!secondChild) {
$('.metafield').css({'width': '100%'});
}
else {
$('.metafield').css({'width': '50%'});
}
Even when there's only one metafield
, it always executes the else
condition! Any ideas on how to fix this?