Reputation: 3321
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?
Upvotes: 0
Views: 896
Reputation: 24832
if you have one td:
$("#displayingText").val($("td").html());
if you have several td:
$("td").each(function(){
$("#displayingText").val($("#displayingText").val()+$(this).html());
});
Upvotes: 1
Reputation: 11327
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.
Upvotes: 2