In my app I have multiple divs which look like (The divs are created dynamically):
<div class="form-group clearfix">
<div class="form-group first-name">
<input type="text" id="firstName0" class="signup-input firstName required" name="first[0]" placeholder="">
</div>
<div class="form-group last-name">
<input type="text" id="lastName0" class="signup-input lastName" name="last[0]" placeholder="optional">
</div>
<div class="form-group email">
<input type="text" data-index="0" id="inputMail0" class="signup-input mail" name="email[0]" placeholder="e.g. [email protected]" aria-invalid="true">
<span class="common-sprite sign-up-cross first"></span>
</div>
</div>
The names are dynamically generated according to the index (For example the are email[1], email[2].....).
I have a button which should be disabled in case the field of the first name is not empty
and the field of the email is empty
and the span hasn't a class of disNone
.
How should I disable the button according to above condition?
Hope this condition works out for you.
Store the jQuery objects in variables and use that variables instead, which is a much better way to do it.
EDIT: If your
DIVS
are being generated dynamically you can use theeach()
jquery function to loop through them.Checkout the FIDDLE LINK
In the fiddle I have left out one
SPAN
tag with classdisNone
and otherSPAN
tag without classdisNone
. So only once the condition executes