gpt4 book ai didi

javascript - jQuery [object Object] 不是有效的选择器

转载 作者:行者123 更新时间:2023-11-30 21:19:14 26 4
gpt4 key购买 nike

我正在尝试选择具有子节点和第一个子节点的树节点元素,但它不是有效的选择器。

<g class="nodes">
<g class="tree-node enter" id="tree-node-cdl3c5he">
<g class="node-group">
<circle class="node-shape" r="80"></circle>
<g class="node-label-group" transform="translate(-80,-80)">
<foreignObject class="node-content-container" width="160" height="160">
<div class="node-content">
<div class="inner">
<div class="node-label" data-test-id="node-label-new-part">New Part</div>
</div></div></foreignObject></g><g class="root-group" transform="translate(0,-80)"><circle class="root-shape" r="15"></circle></g>
</g>
</g>
</g>

使用第一个 child :

$('.nodes > .tree-node:first-child')

Ember 测试:

await click($('.nodes > .tree-node:first-child'));

错误:无法在“Document”上执行“querySelector”:“#ember-testing [object Object]”不是有效的选择器。

最佳答案

$('.nodes > .tree-node:first-child')工作正常并且不是无效的选择器,如下所示。它将返回 .nodes 的第一个 child 同类.tree-node ,如果你想在 .tree-node 中获取第一个 child 那么你需要加一个空格 $('.nodes > .tree-node :first-child')


$('.nodes > .tree-node:first-child')
Expected ► <g class="tree-node enter" id="tree-node-cdl3c5he">

var x = $('.nodes > .tree-node:first-child');
console.log(x)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<g class="nodes">
<g class="tree-node enter" id="tree-node-cdl3c5he">
<g class="node-group">
<circle class="node-shape" r="80"></circle>
<g class="node-label-group" transform="translate(-80,-80)">
<foreignObject class="node-content-container" width="160" height="160">
<div class="node-content">
<div class="inner">
<div class="node-label" data-test-id="node-label-new-part">New Part</div>
</div>
</div>
</foreignObject>
</g>
<g class="root-group" transform="translate(0,-80)">
<circle class="root-shape" r="15"></circle>
</g>
</g>
</g>
</g>


$('.nodes > .tree-node :first-child')
Expected ► <g class="node-group">

var x = $('.nodes > .tree-node :first-child');
console.log(x)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<g class="nodes">
<g class="tree-node enter" id="tree-node-cdl3c5he">
<g class="node-group">
<circle class="node-shape" r="80"></circle>
<g class="node-label-group" transform="translate(-80,-80)">
<foreignObject class="node-content-container" width="160" height="160">
<div class="node-content">
<div class="inner">
<div class="node-label" data-test-id="node-label-new-part">New Part</div>
</div>
</div>
</foreignObject>
</g>
<g class="root-group" transform="translate(0,-80)">
<circle class="root-shape" r="15"></circle>
</g>
</g>
</g>
</g>

关于javascript - jQuery [object Object] 不是有效的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45349830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com