I am using Jquery to dynamically populate the table element. My table will have three columns – Label, textarea and a button. I am binding a click event on click of the button. Below is my Jquery code.
var rowElem = $('<tr id="'+ key + '" class="queryRow"> </tr>');
rowElem.append($('<td class="queryTitleCol">' + key + '</td>'));
var colElem = $('<td class="queryValueCol"></td>');
var textAreaElem = $('<textarea rows="10" cols="75"/>');
colElem.append(textAreaElem);
rowElem.append(colElem);
textAreaElem.val(value);
var btnCol = $(
'<td valign="top">'
+ '<button style="width:42px; vertical-align:middle; margin:2px;" title="delete">'
+ '<span class="ui-icon ui-icon-trash" style="float:left;"/>'
+ '</button>'
+'</td>');
rowElem.append(btnCol);
$("button", btnCol).click(action);
}
In the button event I am using Jqury.closest to get the TR tag and label element. Below is my code for button click.
function action() {
var rowElem = $(this).closest("tr");
var labelTD = $(".queryTitleCol", rowElem);
}
But labelTD , I am always getting as [td.queryTitleCol] as an array. I am not able to get the td element to get the lable element. I tried with find(), but still I am getting as td array.
rowElem.find('td.queryTitleCol');
How can I traverse and get the label name on click function of the button. Any help will be really appreciated.
Try
or