asehgal asehgal - 1 year ago 67
jQuery Question

Cant use find on element textarea which is child of td

I get an error on the line

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');

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

Answer Source

Try to replace:




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

$(targetTD[6]).attr("readonly", false);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download