When i click on expandable-icons-cancel I want to save a child label of form-group div. Here is the structure:
<div class="form-group ">
<label class="" style="padding-top:10px;"> Long Title</label>
<span class="value ">
<div class="expandable">
<div class="expandable-icons">
<img class="expandable-icons-cancel" style="display:none;" src="test/cancel.png">
</div>
</div>
</span>
</div>
And function:
jQuery('.expandable-icons-cancel').click(function() {
var parentDiv = jQuery(this).parents('div.expandable'); //-works, but how can i get upper?
// How to get 2 steps upper to form-group?
// How to get get child label text of form-group and save in var?
}
You can use closest()
, like this
jQuery(this).closest(".form-group");
for the label text you can do...
jQuery(this).closest(".form-group").find("label").text();
if you know label will always be a direct child of .form-group
, you can use children()
in place of find()
. If there is a possible for multiple labels and you only want to get the first, you can place eq(0)
after getting the label.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With