tags:

views:

19

answers:

2

Hi all,

I got a Table with some data inside it like this:

<table>
<tr>
<td>
hello world! I am new to JQuery
</td>
</tr>
</table>

<input type="text" id="displayingText" value="">

I was trying to grab the data in the TD tag of the table and display the data in the Inout Text field.
Is it possible to do it in JQuery in this case?

+2  A: 

For your code you provided, try this.

$(function() {
    $('#displayingText').val( $('table td').text() );
});

If your table changes, the answer will probably need to change too.

Here is an example.

http://jsfiddle.net/9hPG2/

RightSaidFred
+1  A: 

if you have one td:

$("#displayingText").val($("td").html());

if you have several td:

$("td").each(function(){
     $("#displayingText").val($("#displayingText").val()+$(this).html());
});
Gregoire