Javascript 子选择器jQuery

Javascript 子选择器jQuery,javascript,jquery,children,Javascript,Jquery,Children,我有一个jQuery对象包含在中 当我打电话时: console.log($(this).children("td.price.desired").html()); console.log($(this).children("td.price.desired h3").html()); 终端打印: <h3 class="table-label"><span class="label label-default number"> 0 </span></

我有一个jQuery对象包含在

当我打电话时:

console.log($(this).children("td.price.desired").html());
console.log($(this).children("td.price.desired h3").html());
终端打印:

<h3 class="table-label"><span class="label label-default number"> 0 </span></h3>
<input name="trade_params[0][price_desired]" type="number" step="0.01" value="0" min="0.00" class="form-control number" placeholder="Chart Price">
有人告诉我,结果尚未确定

我的理解是,我可以使用这里记录的祖先和孩子的选择器方法:

我可以通过以下方式获得

$(this).children("td.price.desired").children("h3")
第一种方法我做错了什么?对我来说,这两种方法应该是等价的

编辑:

以下是上下文中的完整HTML:

<tr class="0">
    <td class="price desired">
        <h3 class="table-label"><span class="label label-default number"> 0 </span></h3>
        <input name="trade_params[0][price_desired]" type="number" step="0.01" value="0" min="0.00" class="form-control number" placeholder="Chart Price">
    </td>
</tr>

0
只查找元素的直接子元素,在这种情况下需要使用

演示:

试试看

console.log($(this).children("td.price.desired > h3").html());

使用instead但不是
的直系后裔吗?@SavvasNicholas不是
这个
元素所指的
tr
元素的
这个
元素所指的
tr
对吗?所以肯定
h3
tr
的直系后代,或者我完全弄错了吗?@SavvasNicholas抱歉,我想我用了后代把你弄糊涂了,它不是tr的直系子代,
h3
td
的子代,这是
tr
的子代,好的,但是
td.price.desired
是否引用
td
元素,然后
h3
是否应该以该元素的后代为目标?否则,我看不出父后代选择器的意义。在文档中的示例中,它遍历文档树的多个级别。我应该使用
filter
而不是
children
?这与不使用
符号有什么区别?使用>选择器仅获取第一级子项,而不使用它将获取所有子项。
console.log($(this).children("td.price.desired > h3").html());