Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
¿Por qué esto no cambia el a msgTwo en un segundo clic del botón?

¿No debería agregar otra cosa cambiar el contenido de nuevo a Bienvenido a nuestro sitio definido en la variable msgTwo o estoy haciendo esto mal?

 let el = document.getElementById('message'); let butt = document.getElementById('clicktodo') let msg = 'Sign up to our Newsletter for 10% off!'; let msgTwo = 'Welcome to Our Site!'; function change() { if (el != msg) { el.textContent = msg; } else { el.textContent = msgTwo; } }; butt.addEventListener('click', change);
 <body> <h1> Traval Worthy </h1> <div id="message"> Welcome to Our Site! </div> <button id="clicktodo" style ="padding: 10px 15px; margin-top: 15px"> Click Here </button> </body>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En la función de change , use el.textContent para obtener el texto del elemento del mensaje mientras verifica if

 if (el.textContent != msg) { el.textContent = msg; } else { el.textContent = msgTwo; }

También puede reemplazar este if-else con

 el.textContent = el.textContent === msg ? msgTwo : msg;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!