简体   繁体   中英

How to hide a button with .innerHTML?

Is there a way to hide a button with .innerHTML? I tried the following code but it did not work:

 function F1() { bL1 = document.getElementById("bL1").innerHTML = '<body class="hidden">'; ebL1 = document.getElementById("ebL1").innerHTML = '</body>'; }
 .hidden { display: none; }
 <button onclick="F1()">Hide Lw</button> <label id="bL1"></label> <button> Lw </button> <label id="ebL1"></label>

If you are trying in this method you are doing very wrong but use the following code that should work correctly to hide a button or anything you want to hide.

 function F1() { bL1 = document.getElementById("bL1").style.display = 'none'; }
 <button onclick="F1()">Hide Lw</button> <button id="bL1"> Lw </button>

This is a very easy and short method to apply CSS inside JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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