My dom looks like this:
<div class="edit-section slideDown">
<form>
<div class="info-header">
<div class="acct-section-title clearfix">
<h3 class="acct-section-title-txt pull-left">Meals</h3>
<button type="button" class="pull-right btn-close icon-close"></button>
</div>
</div>
<div id="flash-msg"></div>
<ul class="info-list info-list-form">
<div class="col-sm-4 info-label"><label for="delivery_name">Name</label></div>
<div class="col-sm-8 info-value">
<div class="form-group mb-0">
<input type="text" name="delivery_name" id="delivery_name" class="form-input">
</div>
...
How do I use jQuery to check if the input at the bottom has the dom element:
<label for="delivery_name">Name</label>
What's hte best way to check that?
$('.edit-section')
gets me the outer element but then how do I get the label tag?
you can use find for it.
check the following snippet
console.log($(".edit-section").find("label[for =delivery_name]").text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="edit-section slideDown">
<div class="info-header">
<div class="acct-section-title clearfix">
<h3 class="acct-section-title-txt pull-left">Meals</h3>
<button type="button" class="pull-right btn-close icon-close"></button>
</div>
</div>
<div id="flash-msg"></div>
<ul class="info-list info-list-form">
<div class="col-sm-4 info-label">
<label for="delivery_name">Name</label>
</div>
<div class="col-sm-8 info-value">
<div class="form-group mb-0">
<input type="text" name="delivery_name" id="delivery_name" class="form-input">
</div>
</div>
How do I get the label tag?
The most straightforward approach is:
$('label[for="delivery_name"]');
How do I use jQuery to check if the input at the bottom has the label?
If $('label[for="delivery_name"]').length < 1
, then it isn't there.
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