temerariomalaga temerariomalaga - 1 month ago 5
Javascript Question

Get text from td and print it in a input

I've a table and I need to get the text of the td I've clicked and print it in a input box.
Now I've this code but it prints the last value of the table.

$("td").click(function(){
$("td").each(function(index){
$("#prueba").val(($(this).text()));
});
});

Answer

just remove the each, you don't need it!

$("td").click(function(){  
    $("#prueba").val(($(this).text()));
}); 

you can see here the solution: http://jsfiddle.net/GNkxm/

Comments