Find textarea inside a table row and replace it's value with Jquery
html
<tr id="rowID"><td class="from"&g开发者_如何学Got;<textarea class="inputTextarea">text</textarea></td></tr>
provided I know the rowId, how do I replace the text inside textarea?
got it
$("#" + rowId + " textarea.inputTextarea").val(newValue);
You can select the text area in a single CSS based selector, which will return the textarea for the row with rowID. Then we change its text value using the val
jQuery function:
$('#rowID td textarea.inputTextarea').val('value goes here');
you do not need any classes if you have only one td or one textarea. (at least not for jquery)
$('#rowID td textarea').val('VALUE')
if you have multiple textareas, this will replace the value in all of them. if you dont want that make sure to include the specific textarea or td class:
$('#rowID td.from textarea.textArea').val('VALUE');
Edit: for multiple textareas you can alternatively also use other selectors like:
$('#rowID td:eq(2) textarea').val('VALUE')
will change the value in all textareas in the third column of the given row.
Try this:
function changeText(rowID, data)
{
$("#" + rowID + " textarea").val(data);
}
changeText("rowID", data);
精彩评论