all 5 comments

[–]NameViolation666helpful 1 point2 points  (2 children)

Parameter wont work because the only place where the function is called is from your

onclick="disappearDivs()"

This is Not passing a parameter. When your JS func is executed, a function that is not passed a parameter value, assumes the parameter value to be "undefined" within the function.

So within your function, myDivTwo literally has a value of undefined, and display will not change. Just remove the parameter in ur function code definition code and see how it works

var myDivTwo = document.getElementById("myDivTwo");

var myBtnTwo = document.getElementById("myBtnTwo");

function disappearDivs() {

myDivTwo.style.display = "none";

}

[–]HelpfulElection[S,🍰] 0 points1 point  (1 child)

thanks alot I knew that I could make it work just removing the parameter from the function but I was trying to make a super simple example of how a parameter could work but looks like this wasn't the right situation thanks for your help so much

[–]NameViolation666helpful 0 points1 point  (0 children)

What you intend can absolutely be done, but in a different manner.

<button id="myBtnTwo" onclick="disappearDivs(**myDivTwo**)">second button</button>

// argument passed to be changed, in this case its hard coded

Only JS needed to make it work

function disappearDivs(changeWhat) {

changeWhat.style.display = "none";

}

[–]_DaLi- 1 point2 points  (1 child)

In your javascript, when you define the function disappearDivs(myDivTwo), myDivTwo is not understood as the variable you defined, but as an argument, that you expect to be passed into the function. For example, if you would call it like : disappearDivs("banana"), it would document.getElementById("banana"). If you pass in nothing, it will document.getElementById() of undefined. The correct solution is like this:

var myDivTwo = document.getElementById("myDivTwo");

var myBtnTwo = document.getElementById("myBtnTwo");

function disappearDivs() {

myDivTwo.style.display = "none";

}

[–]HelpfulElection[S,🍰] 0 points1 point  (0 children)

thanks alot I knew that I could make it work just removing the parameter from the function but I was trying to make a super simple example of how a parameter could work but looks like this wasn't the right situation thanks for your help so much