Javascript 如何从html中过滤出列表元素以将其从表中消失?
我想用Javascript 如何从html中过滤出列表元素以将其从表中消失?,javascript,html,list,hidden,Javascript,Html,List,Hidden,我想用title=“Datenschutz”捕捉列表并隐藏它。我怎么能这样做 HTML: 此方法使用具有 如果不想删除元素,请将removeChild替换为要隐藏的元素 li.style.display = 'none'; 向我们展示您的尝试。您希望使用或特别避免使用哪些工具?您希望使用服务器端(即php)还是客户端(javascript)?您更喜欢哪种方法?您可以使用css:a[title=Datenschutz]{display:none}隐藏它。它只会隐藏锚点,而不是整个列
title=“Datenschutz”
捕捉列表并隐藏它。我怎么能这样做
HTML:
此方法使用具有
如果不想删除元素,请将removeChild替换为要隐藏的元素
li.style.display = 'none';
向我们展示您的尝试。您希望使用或特别避免使用哪些工具?您希望使用服务器端(即php)还是客户端(javascript)?您更喜欢哪种方法?您可以使用css:a[title=Datenschutz]{display:none}隐藏它。它只会隐藏锚点,而不是整个列表项…太好了。谢谢你提供了最简单的版本。我建议使用@Jason Harwig版本-它更通用,并且可重用
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');
li.style.display = 'none';
var t = document.querySelectorAll('a[title=Datenschutz]');
t[0].parentNode.style.display = "none";