Bug或我的愚蠢

时间:2009-09-13 11:54:16

标签: jquery parent-child

不确定我是否错过了一些东西,但这不起作用:

$(this).children('td.threadtitle a').html('thread title');

然而这确实

$(this).children('td.threadtitle').children('a').html('thread title');

我只是想了解为什么会这样。但这是一个错误吗?

2 个答案:

答案 0 :(得分:2)

.children的选择器参数是过滤器$(this).children('td.threadtitle a')找到与选择器td.threadtitle a 匹配的节点是<{1}}的直接子节点。假设你的标题thistd之内,而不是高于或等于它,这种情况永远不会发生。

我认为你真正想要的是一个情境化选择器:

this

,只要它们出现在$('td.threadtitle a', this).html("Thread title") 下的任何位置,就会找到与该选择器匹配的内容。

答案 1 :(得分:0)

  1. 应该工作。你能上传一些代码,以便我们看到你的HTML吗?
  2. 只需注意:如果您需要children,则应使用"td.threadtitle > a"。其他应该是find('a')