jQuery .nextAll not working?
I got this html
<tr>
<td>
Main Alliase/Current Alliase:
</td>
<td><input type="text" id="maina" class="countchars" max="30"/><br />
<span class="showchars"></span>
</td>
<td><span id="handle-1" class="selector" title="The Main Alliase with which people know you OR the alliase with which u play most <br /> <b>You'r App would be also named after this only</b>" header="Main Alliase/Current Alliase">?</span></td>
<td><div id="error-1" class="errors"></div></td>
</tr>
And this js:
$开发者_如何转开发('#maina').focus(function() {
$(this).closest("tr").find(".selector").qtip('toggle', true);
$(this).nextAll(".errors:first").html("Bla");
$(this).siblings(".showchars").show();
});
But the when i focus into the maina
it does the other 2 things but doesnt changes the html of errors
class.
Why so ? What have i been doing wrong ? Please help me Thanks
I think you should do:
$(this).closest('tr').find(".errors:first").html("Bla");
Yhis is because nextAll() looks for siblings (Get all following siblings of each element in the set of matched elements, optionally filtered by a selector
), and the only sibling of maina is the span
As you can see on this example .nextAll()
only gives you back siblings.
You could use:
$(this).parents("tr").eq(0).find(".errors:eq(0)").html("Bla");
精彩评论