Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of hiding elements in javascript

Shulou Source: shulou.com Published: 2022-06-01 19:26:20 09月24日 Update

This article mainly introduces the relevant knowledge of "the method of hiding elements in javascript". The editor shows you the operation process through the actual case. The method of operation is simple, fast and practical. I hope this article "the method of hiding elements in javascript" can help you solve the problem.

Javascript hide elements: 1, use the "element object .style.display =" none "statement; 2, use the" element object .style.style = "hidden" statement; 3, use the "element object .style.opacity = 0" statement.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Several methods of hiding elements in javascript

First kind

# myBtn {width: 300px; height: 150px; background-color: rgb (16130150); color: coral; font-size: 35px;} Hidden element points I'm surprised! Var btn = document.getElementById ("myBtn") btn.addEventListener ('click', function (event) {document.getElementById ("myBtn"). Style.display = "none";})

The second kind

Hidden element # myBtn {width: 300px; height: 150px; background-color: rgb (220,140,228); color: coral; font-size: 35px;} I'm surprised! Var btn = document.getElementById ("myBtn") btn.addEventListener ('click', function (event) {document.getElementById ("myBtn"). Style.visibility = "hidden";})

The third kind

Hidden element # myBtn {width: 300px; height: 150px; background-color: rgb (192,231,128); color: coral; font-size: 35px;} I'm surprised! Var btn = document.getElementById ("myBtn") btn.addEventListener ('click', function (event) {document.getElementById ("myBtn"). Style.opacity = 0;})

The fourth kind

Hidden element # myBtn {width: 300px; height: 150px; background-color: rgb (156,97,121); color: coral; font-size: 35px;} I'm surprised! Var btn = document.getElementById ("myBtn") btn.addEventListener ('click', function (event) {$("# myBtn"). Hide ();}) this is the end of the introduction on "how to hide elements in javascript". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Elements methods surprises objects knowledge sentences industries different practical content practical practical tutorials articles more cases environment computers knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS NVidia MariaDB Redmi