Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
How to make button change paragraph more than once and in last one change both paragraph and button text?

I really need help with my research project: How to add more paragraphs to change on the click of the button like "Third Paragraph" and "Forth Paragraph" and in the last click the (Forth Paragraph) I want to change the paragraph and button text together, the paragraph to another text and the button from (click) to (Hint)?

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 Respostas
Responde à pergunta

0

this snippet may help you

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 Relatório

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>

You can use arr and index value to set text or button hide

Try This

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda