I have created table row using jquery:
var tableRow = $("<tr>").append($("<td>").text("one"))
.append($("<td>").text("two"))
.append($("<td>").text("three"));
Now I add it to the table in the document:
$("#table_id").append(tableRow);
The next thing I want to do is to set the click events on some of the cells of the tableRow created above. I want to use nth child selector for that purpose. However from the documentation it seems that it is possible to use it with some selectors like :
$("ul li:nth-child(2)")
But now I need to use :nth-child()
for a variable tableRow.
How is it possible?
Your created the element dynamically so you have to use the following structure, if its statically created(ie: created in HTML you can use what your mention for ul)
DEMO
In that case, you can use
.find()
You can use .find() along with nth-child
Or in this case you can use .children(), which might be better
Try with
.eq()
likeOr you can directly call from tableRow like