gpt4 book ai didi

javascript - 使用javascript隐藏特定UL中的href元素

转载 作者:太空宇宙 更新时间:2023-11-04 04:57:22 24 4
gpt4 key购买 nike

我们如何在特定的 UL 元素中隐藏 href 元素(不是在所有 UL 元素中,因为 UL 元素具有相同的名称)。

例如我们有这样的 HTML 代码:

<ul class="UL_tag">
<li>Text 1</li>
<li>Text 2</li>
<li><a href="http://www.google.com" class="description">Link to GOOGLE</a></li>
</ul>

<ul class="UL_tag">
<li>Text 1</li>
<li>Text 2</li>
<li><a href="http://www.yahoo.com" class="description">Link to Yahoo</a></li>
</ul>

我们可以使用以下代码隐藏这些 href:

$('a.description').hide();

如果我只想隐藏一个 UL 元素中的一个 href 元素,我应该如何更改此 javascript 代码?不是所有具有类名“description”的 href 元素?

感谢您的帮助!

最佳答案

您可以使用 attr href 选择器:

$('a[href="http://www.yahoo.com"]').hide();

这是一个示例链接,您可以使用不同的方法:

这个问题也相关:jQuery cant access element with its attr href // simple tabs structure

关于javascript - 使用javascript隐藏特定UL中的href元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12137685/

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