简体   繁体   English

如何设置显示无<footer>用控制台标记?

[英]How To Set Display None of <footer> tag with Console?

I'm trying to hide some fields on sites with javascript.我正在尝试使用 javascript 隐藏网站上的一些字段。 For this, I use the console of the relevant browser and here I make that field display = "none";为此,我使用相关浏览器的控制台,在这里我将该字段设置为 display = "none"; with ClassName or ID, but I made a few attempts to improve these things a little more.使用 ClassName 或 ID,但我做了一些尝试来改进这些东西。

In these experiments, I only found a field with <footer> tag, but it has neither ClassName nor ID.在这些实验中,我只找到了一个带有<footer>标签的字段,但它既没有 ClassName 也没有 ID。

document.getElementsByClassName("footer")[0].style.display = "none";

How can I make it invisible with js code?如何使用 js 代码使其不可见? Thank you very much if you can get back to me.如果您能回复我,非常感谢。 I am trying to learn something new.我正在尝试学习新的东西。

You can use the document.querySelector() function.您可以使用document.querySelector()函数。 This allows you to specify any valid CSS selector, meaning that in this case you can use the element's tag type to identify it.这允许您指定任何有效的 CSS 选择器,这意味着在这种情况下您可以使用元素的标签类型来识别它。

Demo:演示:

 document.querySelector("footer").style.display = "none";
 <div>Another div</div> <footer>Hello</footer>

The code will remove the existing "Hello" message by hiding the footer element.该代码将通过隐藏页脚元素来删除现有的“Hello”消息。 All that's still on display is the "Another div".仍然显示的是“另一个 div”。

Documentation: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector文档: https ://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

You can already create a class in CSS with style display: none;您已经可以在 CSS 中创建一个带有样式 display: none; 的类。 and later add or append that class on the footer,然后在页脚添加或附加该类,

 let element = document.querySelector(".footer"); function hideFooter() { element.classList.add("hide"); }
 .hide { display: none; }
 <footer class="footer"> <!-- footer code --> <p>This Is Footer </p> </footer> <button onClick="hideFooter()"> Hide Footer </button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM