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

156
Views
¿Cómo hacer que el botón cambie el párrafo más de una vez y en el último cambie tanto el párrafo como el texto del botón?

Realmente necesito ayuda con mi proyecto de investigación: Cómo agregar más párrafos para cambiar al hacer clic en el botón como "Tercer párrafo" y "Cuarto párrafo" y en el último clic en (Cuarto párrafo) Quiero cambiar el párrafo y el botón texto juntos, el párrafo a otro texto y el botón de (clic) a (Sugerencia)?

 var time = 0; function changeText(txt) { var txt = (time === 0) ? "First Paragraph" : "Second Paragraph"; document.getElementById('name').innerHTML = txt; time++; }
 <body> <p> <b id='name'>{description}</b>. </p> <input type='button' onclick='changeText()' value="click" /> <br /><br /> </body>

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

0

este fragmento puede ayudarte

 let time = 0; const paragraphs = ["First", "Second", "Third", "Fourth"]; function changeText() { let text = `${paragraphs[time]} Paragraph`; if (text === "Fourth Paragraph") { document.getElementById('name').innerHTML = "another text"; document.getElementById('btn').value = "Hint" } else { document.getElementById('name').innerHTML = text; } if (paragraphs[time + 1]) { time++; } }
 <p><b id='name'>{description}</b>.</p> <input type='button' onclick='changeText()' value="click" id="btn" /> <br /><br />

about 4 years ago · Juan Pablo Isaza Report

0

JS

 var index = 0; var arr = ["First Paragraph","Second Paragraph","Third Paragraph","Forth Paragraph"]; function changeText(element){ if(index < arr.length){ document.getElementById('name').innerHTML = arr[index]; }else{ element.style.display = "none"; } index++; }

HTML

 <body> <p> <b id='name'>{description}</b>. </p> <input type='button' onclick='changeText(this)' value="click"/> <br /><br /> </body>

Puede usar arr y valor de índice para configurar el texto o ocultar botones

Prueba esto

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!