When querying the DOM, is there any reason why labels aren't available as children?
var el = document.getElementById("myEl");
var group = el.closest(".form-group");
var ipt = el.closest(".form-group > input");
var lbl = el.closest(".form-group > label");
console.log(ipt);
console.log(lbl);
<div class="row">
<div class="form-group col-sm-6">
<label>Name
<i class="fa fa-asterisk text-danger"></i>
</label>
<input type="text" class="form-control" id="myEl" value.bind="location.name & validate">
</div>
</div>
label
is a sibling of the input, not a parent/ancestor developer.mozilla.org/en-US/docs/Web/API/Element/closest – Spill<input>
? Note that "The Element.closest() method returns the closest ancestor of the current element (or the current element itself) which matches the selectors given in parameter." The<input>
itself is returned because it matches the> input
selector, but it doesn't match the> label
selector. – Semipalatinsk