Reputation: 5036
alert($('.input-large[name="name"]:parent:parent').html());
My html is :
<div class="control-group">
<label for="name" class="control-label">Clinic Name</label>
<div class="controls">
<input type="text" name="name" id="name" class="input-large" value="">
</div>
</div>
I'm getting null in the alert. How to find the parent of the parent of the input element?
Upvotes: 0
Views: 212
Reputation: 8301
You could do the parent().parent() chain as others have done, or just pass the parent selector into .parents() for a cleaner chain, like so:
alert( $('#name').parents('.control-group').html() );
Upvotes: 1
Reputation: 1684
For all input-large[name=name]
elements:
$(".input-large[name=name]").each(function(){
alert($(this).parent().parent().html());
});
But then again this will give you an alert for each instance.
Upvotes: 1