In your case use the Parent to select the tr
father of td
that was clicked, after accessing the tr
use the function find to select the td's
daughters and use selector :Nth-Child() to select each column of the selected row.
$('#tableTime tr td').click(function() {
var content = $(this).parent().find(':nth-child(1)').text();
$("#descricaoAgenda").val(content);
});
Tip: You can use the click event directly in the table row $('table tr').on('click', callback)
, this way, you will not need to use the parent()
.
See the example changed by tip, without using the parent
$('table tr').on('click', function() {
var content1 = $(this).find(':nth-child(1)').text();
var content2 = $(this).find(':nth-child(2)').text();
$("#txtResultado1").val(content1);
$("#txtResultado2").val(content2);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
</tr>
</table>
<input type="text" id="txtResultado1" />
<input type="text" id="txtResultado2" />
Fernando, so there is no confusion in the understanding of your question, I suggest you post also your HTML and try to describe in more detail what you are trying to do. :)
– Pedro Camara Junior
It had put the wrong answer, but if you have mounted your html at runtime here you can get a sense of how to do it. http://answall.com/questions/65204/criar-um-link-que-ao-ser-clicado-pego-o-seu-texto/65209#65209
– Marconi
put the html
– Fernando Fefu