I have the following code:
function my() {
var x = document.getElementById("open");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
.box-content-text-btn{
background: transparent;
border: 0;
padding: 0;
}
<html>
<head>
</head>
<body>
<button type="button" onclick="my()"><i class="fas fa-plus"></i>botón</button>
<div id='open' style='display: none;'>
<h1>Test</h1>
</div>
</body>
</html>
It happens that when I click the button to open the div it doesn't work, but if I click it again it works... that is, I have to click the button 2 times to activate the function. I want to know how can I solve this
It works fine for me