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

133
Vistas
Changing an <a> tag with javascript

I need to change an anchor tag from this

<a href="#" id="masini">Mașini <i class="bi bi-caret-right"></i></a>

to this

<a href="#" id="masini">Mașini <i class="bi bi-caret-down"></i></a>

when the screen gets smaller. Basically to be responsive. I need to use javascript btw.

I tried the code bellow but it's not working.

if(window.innerWidth < 1130px)
        {
            var replace = "Mașini"
            replace += "<i class="bi bi-caret-down"></i>";
            document.getElementById("masini").innerHTML = replace;
        }
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

I'd recommend targeting the <i> element and changing it's class:

if (window.innerWidth < 1130) {
    const iElement = document.querySelector("#masini i");
    iElement.classList.replace("bi-caret-right", "bi-caret-down");
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

It would help to do the following:

if (window.innerWidth < 1130) {
  document.getElementById("masini").className = "bi bi-caret-down";
}
<a href="#">Mașini <i id="masini" class="bi bi-caret-right"></i></a>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to delimit your double quotes or wrap with single quotes.

replace += '<i class="bi bi-caret-down"></i>';

OR:

replace += "<i class=\"bi bi-caret-down\"></i>";
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