Reputation: 39384
I have the following markup example:
<div class="wrap">
<input name="country"/>
<span class="message">Fill your country</span>
<span class="error">Error</span>
</div>
The error span can be immediately after the input or not.
Being element
then country input I have to get the error span:
var error = element.parent().children("span.error");
This is working but does not feel right ... Is there a better way?
Basically, I need to get the first span.error after 'input.country'.
Upvotes: 0
Views: 35
Reputation: 8545
var error = element.siblings("span.error:first");
Use siblings method.
Upvotes: 0
Reputation: 15112
To get the first error span
element.siblings("span.error:first")
To get all error spans
element.siblings("span.error")
Upvotes: 1