I can't change permanently the background color of a simple html page using javascript

when I click in the button the backgrounf color of the change but after one seconde it disappear

this is the code

<!DOCTYPE html>
<html>
    <head>
        <title>ex7</title>
        <meta charset="utf-8"> 
        <script>
            function changerCouleur() {
                document.bgColor= "#FFFggF";
            }
        </script>
    </head>
    <body>
      <form>
          couleur  <input type="text" > <br>
          <button onclick="changerCouleur()">changer couleur </button>
      </form>
    </body>
</html>

6 thoughts on “I can't change permanently the background color of a simple html page using javascript”

  1. #FFFggF is not a valid color code.

    Please try this code:

    function changerCouleur() {
                    document.body.style.background = "#ff9933";
                }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!DOCTYPE html>
    <html>
        <head>
            <title>ex7</title>
            <meta charset="utf-8"> 
        </head>
        <body>
          <form onSubmit="return false">
              couleur  <input type="text" > <br>
              <button onclick="changerCouleur();">changer couleur </button>
          </form>
        </body>
    </html>

    I added the attribute onSubmit="return false" to the form because otherwise every time you click on the button the page is reloaded

    Reply
  2. therapie comportementale et cognitive en ligne pharmacie de garde suresnes pregabalin contraindications ati , therapie kalash criminel pharmacie uckange . pharmacie leclerc ibos therapie comportementale et cognitive var , pharmacie illkirch pharmacie thoraval brest pharmacie permanence avignon pharmacie lafayette halles . pharmacie albigny annecy le vieux pharmacie potin beaulieu , pharmacie de garde marseille st antoine traitement reflux gastrique . pharmacie angers ralliement pharmacie aix en provence ouverte le dimanche , pharmacie jeanne d’arc medicaments jambes lourdes sans ordonnance pharmacie bourges rue jean baffier pharmacie angers chu . hypnose & therapies breves – guignard s. troyes pharmacie bordeaux de garde , pharmacie de garde wittenheim pharmacie argenteuil ouvert dimanche . therapie de couple rennes pharmacie lafayette creer un compte , therapies comportementales pharmacie de garde marseille castellas therapies katy pharmacie europe angers .

    Reply

Leave a Comment