2

function button1() {
    document.getElementById("id1").style.visibility = "hidden";
}
.d1 {
    font-family: "Aldrich";
    font-size: 50px;
}
<link href="https://fonts.googleapis.com/css?family=Aldrich" rel="stylesheet">

<div class="d1" id ="id1">Test</div>

<button onclick="button1">Button 1</button>

I use the above simple code to set the visibility of a div to hidden via a button. I click on it but nothing happens. If I set the property visibility: hidden; directly to d1 it does work though...

Phil
  • 157,677
  • 23
  • 242
  • 245
darkchampionz
  • 1,174
  • 5
  • 24
  • 47

2 Answers2

3

Here you go with a solution

function button1() {
  document.getElementById("id1").style.visibility = "hidden";
}
.d1 {
    font-family: "Aldrich";
    font-size: 50px;
}
<div class="d1" id ="id1">Test</div>

<button onclick="button1()">Button 1</button>

You forgot to call the method from button click. For calling a method button1()

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
2

missing the button1() on your html <button>

function button1() {
    document.getElementById("id1").style.visibility = "hidden";
}
.d1 {
    font-family: "Aldrich";
    font-size: 50px;
}
<div class="d1" id ="id1">Test</div>

<button onclick="button1()">Button 1</button>
OmmiZone
  • 76
  • 3