gpt4 book ai didi

javascript - 如何从 html 中过滤掉列表元素以将其从表中消失?

转载 作者:行者123 更新时间:2023-11-30 12:50:04 26 4
gpt4 key购买 nike

我想用 title="Datenschutz" 捕获列表并隐藏它。我怎么能这样做?

HTML:

<div id="Footer">
<ul>
<li><a href="#" title="AGB">AGB</a></li>
<li><a href="#" title="Impressum">Impressum</a></li>
<li><a href="#" title="Datenschutz">Datenschutz</a></li>
<li><a href="#" title="Copyrightbestimmungen">Copyrightbestimmungen</a></li>
</ul>
</div>

最佳答案

此方法使用 document.querySelector,它有 decent modern browser support

function removeListElementWithTitle(title) {

// Find anchor elements with specified title attribute
var foundAnchor = document.querySelector('a[title=' + title +']');
if (foundAnchor) {

// Get the anchors parent and remove it from the DOM
var li = foundAnchor.parentNode;
li.parentNode.removeChild(li);
}
}

removeListElementWithTitle('Datenschutz');

如果您不想删除元素,请将 removeChild 替换为隐藏元素。

li.style.display = 'none';

http://jsfiddle.net/r3WQr/

关于javascript - 如何从 html 中过滤掉列表元素以将其从表中消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21263724/

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