2014-12-09 41 views
-2

我想要一个特定元素的特定子元素,我不知道该怎么做。
我试过如下:
$(document.getElementById(tableID).getElementsByTagName("th :a")).each(function(){

$(document.getElementById(tableID).getElementsByTagName("th").getElementsByTagName("a")).each(function(){

$(document.getElementById(tableID).getElementsByTagName("th a")).each(function(){

$(document.getElementById(tableID).getElementsByTagName("th").find("a")).each(function(){JQuery元素通过标记名称两次

这甚至可能,还是我把它的错误的方式?

+0

它会很好,如果你创建一个小提琴来显示你的问题 – 2014-12-09 13:14:09

+1

getElementsByTagName不是由jQuery定义的函数。 (): '$(document.getElementById(tableID)''返回一个jQuery对象。 – ray 2014-12-09 13:17:24

+0

既不是jquery也不是javascript。你应该去基本的第一个。 – asimshahiddIT 2014-12-09 13:18:39

回答

4

您有不正确的选择器来定位锚元素。你可以简单地使用:

$('#'+tableID+' th a').each(function(){ 
    //do something 
}); 
+1

你是非常快的队友无法与你竞争(:+1 – 2014-12-09 13:15:43

+0

This完美的作品,但是我的代码有什么问题? – Grafit 2014-12-09 13:20:06

+0

可以帮助你重现问题。 – 2014-12-09 13:20:36

0

您可以使用$ .find()

$("#" + tableID).find("th").find("a").each(function() {...}); 

$("#" + tableID + " th a").each(function() {...}); 

此外,还可以使用.children()要获取的只是下的节点父节点。

相关问题