asehgal asehgal - 3 months ago 8
jQuery Question

Cant use find on element textarea which is child of td

I get an error on the line

targetTD[6].find('textarea').text()
saying targetTD[6].find is not a function. (In 'targetTD[6].find('textarea')', 'targetTD[6].find' is undefined)

$(document).ready(function () {
$(document.body).on('click','.edit',function () {// use button class ince ID has to be unique per button
var targetTD;
if( $(this).find('i').hasClass('glyphicon-edit'))
{
targetTD = $(this).parents('tr').find('td'); // gives all TDs of current row
if (targetTD[6].firstChild.children.length) // the value cell is what we want
{
// targetTD[6].firstChild.children.item().setAttribute('readonly','false');
alert(targetTD[6].find('textarea').text());
}


I am trying to find a text area within a
<td><div> <textarea readonly> some text </textarea><div><td>
. How can I remove the
readonly
property ? Why cant I use find ?

Answer

Try to replace:

targetTD[6].find('textarea').text();

With:

$(targetTD[6]).find('textarea').text();

Because targetTD is an array with not wrapped elements. Also, to remove readonly property use:

$(targetTD[6]).attr("readonly", false);
Comments