Jquery 虫子还是我的愚蠢

Jquery 虫子还是我的愚蠢,jquery,parent-child,Jquery,Parent Child,不确定我是否错过了什么,但这不起作用: $(this).children('td.threadtitle a').html('thread title'); 然而,这的确如此 $(this).children('td.threadtitle').children('a').html('thread title'); 我只是想弄明白为什么会这样。但这是一个错误吗 应该有用。你能上传一些代码让我们看到你的html吗 请注意:如果您想要孩子,应该使用“td.threadtitle>a”。否则它应该

不确定我是否错过了什么,但这不起作用:

$(this).children('td.threadtitle a').html('thread title');
然而,这的确如此

$(this).children('td.threadtitle').children('a').html('thread title');
我只是想弄明白为什么会这样。但这是一个错误吗

  • 应该有用。你能上传一些代码让我们看到你的html吗
  • 请注意:如果您想要
    孩子
    ,应该使用
    “td.threadtitle>a”
    。否则它应该是
    find('a')

  • .children
    的选择器参数是一个过滤器
    $(this).children('td.threadtitle a')
    查找与选择器
    td.threadtitle a
    匹配的节点,这些节点是
    this
    的直接子节点。假设您的threadtitle
    td
    s位于
    this
    内,且不高于或等于它,则这种情况永远不会发生

    我认为您可能真正想要的是一个上下文化的选择器:

    $('td.threadtitle a', this).html("Thread title")
    

    只要它们出现在
    this

    下的任何位置,它就会找到与该选择器匹配的内容。$(this).children('td.threadtitle a')的唯一工作方式是如果$(this)是的话。我相信你是对的,
    children
    的过滤器不应该再降低一级。接得好。