Hide my div on page load

Solved
Aaymeric Posted messages 83 Status Member -  
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
 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

  1. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
     
    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 div
     function showHide(idDiv) { var div = document.getElementById(idDiv); if (div.style.display == ""){ div.style.display = "none"; }else{ div.style.display = ""; } } 


    Best regards,
    Jordane
    2
    1. Aaymeric Posted messages 83 Status Member
       
      It was all quite silly :) Thank you ;)
      0
      1. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830 > Aaymeric Posted messages 83 Status Member
         
        If the question is resolved..
        Please do not forget to close the topic
        (by clicking on the "Mark as resolved" link located under the title of the question)

        Best regards,
        Jordane
        0
  2. Aaymeric Posted messages 83 Status Member
     
    ```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 */
    }
    ```
    -1
    1. jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
       
      not like this...
      you need the source code that generates your div.
      On the other hand... this... is a new question... you must therefore close this topic and open a new discussion... (this makes it easier to search the forum)
      0