/ / Como selecionar célula diferente da mesma linha em jQuery? - jquery, html-table, jquery-selectors

Como selecionar uma célula diferente da mesma linha no jQuery? - jquery, html-table, jquery-selectors

Eu tenho este seletor de jQuery:

"table tbody tr td:first-of-type"

Como posso construir um seletor de célula para a mesma linha de $ (this)? Eu preciso checar

 $(document).on("click","table tbody tr td:first-of-type",function()
{
if ( $("table tbody tr td:nth-child(2)").text() != "" ) // for the same row !!
//do something
else
//do something else
}

Pergunta extra: devo evitar usar seletores CSS3 como nth-child () e usar seletores jquery como eq ()?

Respostas:

4 para resposta № 1

Basta encontrar o mais próximo tr

$(this).closest("tr")

E para selecionar um td, usar .find() acorrentado a isso:

$(this).closest("tr").find("td") //and whatever criteria you need

0 para resposta № 2

Código de trabalho:

   <html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
if ($("table tbody tr td:nth-child(2)").text() != "" ){ // for the same row
//do something
// alert($("table tbody tr td:nth-child(2)").text());
}else{
//do something else
//alert("test");
}

});
</script>

</head>
<body>
<table>
<tbody>
<tr>
<td>itemOne</td>
<td>itemOneInfo</td>
<td>Info</td>
</tr>
</tbody>
</table>
</body>
</html>