Hide my div on page load
Solved
Aaymeric
Posted messages
83
Status
Member
-
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
Hello everyone,
I don't know anything about JavaScript, but while searching a bit, I found a script that allows me to click a button to show or hide a div.
This script works very well, but I would like to hide this div when the page loads and show the text by clicking the button. I'm sure it's nothing complicated, but I don't know what I need to modify ...
Here is my script
I don't know anything about JavaScript, but while searching a bit, I found a script that allows me to click a button to show or hide a div.
This script works very well, but I would like to hide this div when the page loads and show the text by clicking the button. I'm sure it's nothing complicated, but I don't know what I need to modify ...
Here is my script
function affCache(idDiv) { var div = document.getElementById(idDiv); if (div.style.display == "") div.style.display = "none"; else div.style.display = ""; } function affCacheHidden(idDiv) { var div = document.getElementById(idDiv); if (div.style.visibility == "") div.style.visibility = "hidden"; else div.style.visibility = ""; } function affCacheV(idDiv) { var div = document.getElementById(idDiv); if (div.style.width == "") div.style.width = "0"; else div.style.width = ""; }
2 answers
-
Hello,
I would like to hide this div as soon as the page loads
You just need to set the style: display:none directly on your div
<div id="id_of_your_div" style="display:none"> </div>
So, here is the JavaScript code you can use later to show/hide this divfunction showHide(idDiv) { var div = document.getElementById(idDiv); if (div.style.display == ""){ div.style.display = "none"; }else{ div.style.display = ""; } }
Best regards,
Jordane -
```css
div {
background-color: #yourColor; /* Remplacez #yourColor par la couleur souhaitée */
border: none; /* Supprime les bordures */
box-shadow: none; /* Supprime les ombres si nécessaire */
}
button {
display: none; /* Cache le bouton */
}
```