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

366
Visualizações
Make "a" tags, whenever it is clicked, add inner text inside it, but remove when another "a" tag (same class) is clicked

I'm making a Color Change function for my project. This is my html: click to see it

As title, I want to create some tags which have the same class like this: <a class="dropdown-item" onclick...></a>

And whenever a user click on 1 of those tags, that tag the user clicked will have an extra text [current] like this: Sky [current]. But when another tag is clicked, the text [current] will move to the new tag (with the same class) which the user just clicked.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One simple approach is to just remove the extra text from every clickable element, then add it to the one that was clicked.

Here's an example.

function addText(event) 
{
  for (anchorTag of document.getElementsByClassName("myButton")){
    anchorTag.innerHTML = anchorTag.innerHTML.replace(" Grape", "");
  }
  event.target.innerHTML = event.target.innerHTML + " Grape";
}
<a href="#" class="myButton" onclick="addText(event)">Apple</a>
<br/>
<a href="#" class="myButton" onclick="addText(event)">Orange</a>

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