gpt4 book ai didi

Javascript getElementsByTag 名称

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

我正在尝试使用 getElementsByTagName("a") 方法获取特定标签下的所有元素。

但是,我不想要每个 anchor 标记。我该如何缩小范围,以便只选择“someListClass”名称的 ul 标签下的所有 anchor 标签?

<ul class="someListClass"> <li><a href... /></li>... </ul>

我知道在 jQuery 中你可以用 $(".someListClass a") 来选择。

如果不使用 jQuery,我该怎么做?

最佳答案

给你的ul一个id然后使用

<ul id="ulid" class="someListClass"> <li><a href... /></li>... </ul>

document.getElementById ( "ulid" ).getElementsByTagName ( "a" );

element.getElementsByTagName

elements = element.getElementsByTagName(tagName); 

elements is a live NodeList of found elements in the order they appear in the subtree.

element is the element from where the search should start. Note that only the descendants of this element are included in the search, but not the element itself.

tagName is the qualified name to look for. The special string "*" represents all elements. For compatibility with XHTML, lower-case should be used.

关于Javascript getElementsByTag 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1666881/

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