Home >Web Front-end >JS Tutorial >How to hide a tag in javascript
JS method to hide a tag: 1. Use the "a tag object.style.display="none"" statement; 2. Use the "a tag object.style.visibility="hidden"" statement; 3 , use the "a label object.style.opacity=0" statement.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript hides a tag
Method 1: Use the display attribute
<a href="#" id="a">a标签超链接</a><br /><br /> <input type="button" value="点击按钮进行隐藏" id="btn" /> <script> function my(id) { return document.getElementById(id); } my("btn").onclick = function() { my("a").style.display = "none"; } </script>
Rendering:
Method 2: Using the visibility attribute
<a href="#" id="a">a标签超链接</a><br /><br /> <input type="button" value="点击按钮进行隐藏" id="btn" /> <script> function my(id) { return document.getElementById(id); } my("btn").onclick = function() { my("a").style.visibility="hidden"; } </script>
Rendering:
Method 3: Using the opacity attribute
<a href="#" id="a">a标签超链接</a><br /><br /> <input type="button" value="点击按钮进行隐藏" id="btn" /> <script> function my(id) { return document.getElementById(id); } my("btn").onclick = function() { my("a").style.opacity=0; } </script>
Rendering:
[Recommended learning: javascript Advanced Tutorial】
The above is the detailed content of How to hide a tag in javascript. For more information, please follow other related articles on the PHP Chinese website!