gpt4 book ai didi

javascript - 我怎样才能只得到第一层的元素?

转载 作者:数据小太阳 更新时间:2023-10-29 02:18:29 27 4
gpt4 key购买 nike

所以,我有这个 xml

<conversation>
<question>
<title>I want to get this parent</title>
<question>
<title>I don´t want to get this one</title>
</question>
<question>
<title>I don´t want to get this one</title>
</question>
</question>

<question>and get this one</question>
<question>and also this one too</question>
</conversation>

我想获得顶层,直接从 <conversation> 下降而不是从任何其他标签下降...我怎样才能只得到那些 3 <question>节点?

最佳答案

document.querySelectorAll('对话 > 问题')

the > 表示直子。

example here只是为了避免混淆:

console.log( 
document.querySelectorAll('conversation > question')
)
<conversation>
<question>
<title>I want to get this parent</title>
<question>
<title>I don´t want to get this one</title>
</question>
<question>
<title>I don´t want to get this one</title>
</question>
</question>

<question>and get this one</question>
<question>and also this one too</question>
</conversation>

关于javascript - 我怎样才能只得到第一层的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41163246/

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