Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从html中过滤出列表元素以将其从表中消失?_Javascript_Html_List_Hidden - Fatal编程技术网

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";