2011-08-02 9 views
5

Tengo este htmljQuery .next¿Todo no funciona?

<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> 

Y esto JS:

$('#maina').focus(function() { 
$(this).closest("tr").find(".selector").qtip('toggle', true); 
    $(this).nextAll(".errors:first").html("Bla"); 
    $(this).siblings(".showchars").show(); 
}); 

Pero el cuando me concentro en el maina que hace las otras 2 cosas pero tampoco cambia el código HTML de errors clase.

¿Por qué? ¿Qué he estado haciendo mal? Por favor, ayúdame Gracias

Respuesta

3

creo que debe hacer:

$(this).closest('tr').find(".errors:first").html("Bla"); 

yhis se debe a nextAll() busca hermanos (Get all following siblings of each element in the set of matched elements, optionally filtered by a selector), y el único hermano de Maina es el lapso

+0

He intentado esto pero con un pequeño cambio i putt 'div' en lugar de 'tr' – kritya

+0

Si utiliza TR que está seguro de obtener el div con el error de clase en el misma fila –

+0

¿Pero por qué el div no me da el mismo resultado? – kritya

1

Como usted puede ver en this example.nextAll() solo le devuelve hermanos.

que puede usar:

$(this).parents("tr").eq(0).find(".errors:eq(0)").html("Bla");