I'm trying to determine if there is exactly one div with an error class. If so, I want to use the .select()
method to select the content of the corresponding input (within that input's parent div).
Any ideas on how to achieve this?
This is my attempt which isn't working as expected:
if($("div.addition.error").length === 1) {
$(this).parent().find('input').select();
}
HTML Code
<form>
<div class="input">
<input type="text">
<div>
<div class="addition">Message message.</div>
</div>
</div>
<div class="input">
<input type="text">
<div>
<div class="addition">Message.</div>
</div>
<div class="input">
<!-- The content of this input will be selected in this scenario -->
<input type="text">
<div>
<div class="addition error">Error message.</div>
</div>
</div>
</form>