Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a button invisible by clicking another button in HTML

How can I make a button invisible by clicking another button in HTML?
I have written like below, but it doesn't work.

<input type="button" onclick="demoShow();" value="edit" />
<script type="text/javascript"> 
    function demoShow()
    { document.getElementsByName('p2').style.visibility="hidden"; }
</script>
<input id="p2" type="submit" value="submit" name="submit" />
like image 901
Nasrin hakim Mithila Avatar asked Dec 19 '11 04:12

Nasrin hakim Mithila


People also ask

Can you make a button invisible in HTML?

A hidden attribute on a <button> tag hides the button. Although the button is not visible, its position on the page is maintained.

How do you make a button invisible in JavaScript?

style. display = "none"; // or button. visibility = hidden; This code may help you.


2 Answers

write this

To hide

{document.getElementById("p2").style.display="none";}

to show

{document.getElementById("p2").style.display="block";}
like image 67
Sonal Khunt Avatar answered Nov 15 '22 17:11

Sonal Khunt


Use the id of the element to do the same.

document.getElementById(id).style.visibility = 'hidden';
like image 28
check123 Avatar answered Nov 15 '22 17:11

check123