Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

367
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda