【问题标题】:Javascript Change Child node visibility to hidden in an ulJavascript将子节点可见性更改为隐藏在ul中
【发布时间】:2021-03-21 20:42:33
【问题描述】:

我有以下结构:

看起来像这样:

我想知道如何从那里删除或隐藏“Test1”。

我尝试过使用

document.getElementsByClassName('ms-core-suiteLinkList')[0].childNodes[0].style.visibility='hidden'

但它不起作用,因为它说:“Uncaught TypeError: Cannot read property 'childNodes' of undefined.

使用

 jQuery(".ms-core-suiteLink")[0].remove();

也没有用。

感谢任何帮助!

【问题讨论】:

  • 你可以这样试试吗:jQuery(".ms-core-suiteLink:first > a").hide(); ?
  • 这也删除了“MySite”
  • 您可以将您的 html 显示为文本吗?或者试试jQuery(".ms-core-suiteLinkList:first .ms-core-suiteLink:first > a").hide();

标签: javascript html jquery css dom


【解决方案1】:

你可以试试

document.getElementsByClassName('ms-core-suiteLink-a')[0].style.display = 'none';

document.getElementsByClassName('ms-core-suiteLink-a')[0].style.visibility = "hidden";

他们应该做这项工作。

【讨论】:

  • 第一个不行。第二个有效,但它删除了“MySite”而不是 Test
  • 我真的不知道为什么它不适合你。你能分享你的代码吗?会容易很多
猜你喜欢
  • 1970-01-01
  • 2013-06-01
  • 1970-01-01
  • 2014-05-02
  • 2012-06-08
  • 2010-11-02
  • 2018-05-17
  • 1970-01-01
  • 2013-12-01
相关资源
最近更新 更多