In your case, use the parent to select the tr
parent of the td
that was clicked, after accessing tr
use the find function to select the td's
daughters and use the 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 on the line of the $('table tr').on('click', callback)
table, so you do not need to use parent()
.
See example changed by hint , without using 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><inputtype="text" id="txtResultado1" />
<input type="text" id="txtResultado2" />