Tuesday, 16 August 2022

my html and javascript button to change language doesn't work

I would like to know if any of you can help me and tell me why my code does not work. What I want to do is that when I press the EN button, the language is changed to English and when I press the ES button, the language is changed to Spanish. The problem is that the javascript code that I have made does not work.

    <div class="switch">
               <input id="language-toggle" class="check-toggle check-toggle-round-flat" type="checkbox">
               <label for="language-toggle"></label>
               <span class="on" id="en">EN</span>
               <span class="off" id="es">ES</span>
</div>
<h1 id="hey"> Hey, I'm  English</h1>
 <div>
 <p id="text">I am a text in the English language
</p>
</div>

const english = document.getElementById("en")
const espanol = document.getElementById("es")
const projects = document.getElementById("hey")
const contact = document.getElementById("text")



english.addEventListener("click", function() {
    change(english, espanol);
  }
);

espanol.addEventListener("click", function() {
    change(espanol, english);
  }
);

function change(lang1, lang2) {
  
  if (lang1.innerHTML == "EN") {
    
    hey.innerHTML = "Hey, I'm  English";
    text.innerHTML = "I am a text in the English language";
    
  }
   else  {
    hey.innerHTML = "Hey, yo soy EspaƱol";
    text.innerHTML = "Yo soy un texto en el idioma ingles ";
    }
}

https://codepen.io/Skyance11441/pen/gOeQPJO



from my html and javascript button to change language doesn't work

No comments:

Post a Comment