有什么方法可以删除页面所有元素中的“隐藏”属性?

问题描述

我一直在尝试创建一个书签来取消隐藏网页上的所有内容,但没有成功。这是我到目前为止的代码

document.getElementsByTagName(*)[0].removeAttribute("hidden")

我该怎么做才能取消隐藏所有元素?

编辑:我在下面链接的问题中找到了一行代码,感谢您的帮助!

<p>Hi there</p>
<p hidden>This is hidden p text</p>
<b hidden>This is also hidden text with the bold tag</b>
<br><br/>

<button onclick="unhide()">Click Me</button>

<script>
  function unhide() {
    document.querySelectorAll("*").forEach(b => b.removeAttribute('hidden'));
  }
</script>

解决方法

看看Find and remove attribute on all elements of a certain type

最好的问候