gpt4 book ai didi

javascript - 如何在原型(prototype)中查找没有ID的嵌套html元素

转载 作者:行者123 更新时间:2023-11-28 21:07:39 25 4
gpt4 key购买 nike

<div id="content_heading">
<span id="status">
<h1><em>Some Element</em></h1>
</span>
</div>

我想获取 h1 ,但 $('span h1') 不起作用。另外 $$('h1') 返回一个数组,我可以从数组中获取第一个元素 $$('h1')[0]有没有办法找到更准确的元素,例如 $('div#content_heading span h1')

最佳答案

确保在 DOM 准备就绪后运行代码:

document.observe("dom:loaded", function(){
var header = $$("span h1")[0];
});

参见示例here .

关于javascript - 如何在原型(prototype)中查找没有ID的嵌套html元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9487109/

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