selector - Finding a parent with jQuery -
i have code below:
<div class="as-mobile-item as-mobile-question"> <label>test</label> <div> <textarea name="as_items" class="form-control input-lg as-task-input as-section-ending" rows="3"></textarea> </div> </div>
given as-section-ending
, selector can use highest level div
? 1 classes as-mobile-item as-mobile-question
?
i can't use selector classes because exist elsewhere. need div
classes have as-section-ending
child.
thanks
use .closest
like this
$(function() { var $parentdivs = $(".as-section-ending").closest("div.as-mobile-item.as-mobile-question"); alert($parentdivs.find("label").text()); // example });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="as-mobile-item as-mobile-question"> <label>elsewhere</label> </div> <div class="as-mobile-item as-mobile-question"> <label>test</label> <div> <textarea name="as_items" class="form-control input-lg as-task-input as-section-ending" rows="3"></textarea> </div> </div>
Comments
Post a Comment