如何获得第n个孩子在一个新的元素的jquery [英] How to get nth child in jquery of a new element
本文介绍了如何获得第n个孩子在一个新的元素的jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用jquery创建了表格行:
var tableRow = $(< tr& $(< td>)。text(one))
.append($(< td>).text(two))
.append < td>)text(three));
现在我将它添加到文档中的表:
$(#table_id)。append(tableRow);
接下来我要做的是在tableRow的某些单元格上设置点击事件创建上面。我想使用第n个孩子选择器为此目的。但是从文档看来,它可以使用它与一些选择器如:
$(ul li:nth- (2))
但现在我需要使用:nth- child()
为一个变量tableRow。
.find()$ c $ c> cell = tableRow.find(':nth-child(2)');
cell.on('click',function(){
...
});
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?
解决方案 You can use .find()
cell = tableRow.find(':nth-child(2)');
cell.on('click', function() {
...
});
这篇关于如何获得第n个孩子在一个新的元素的jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文