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

197
Vistas
How can I add an HTML element after another one in javascript?

So I have a pagination with numbers, like in the photo below: enter image description here

And I need to add three dots after "1" like after "5" when I click on 5 or 10, like in the photo below: enter image description here

I tried to do it with insertAdjacentElement like in a function below:

ulTag.addEventListener('click', (e) =>{
        myFunction(e);
    })
    function myFunction(e) {
        let elems = document.querySelector('.active');
        if (elems !== null) {
          elems.classList.remove('active');
        }
         e.target.classList.toggle('active');       
         pageCall(e.target.innerText);
         let dots = document.getElementsByClassName('dots');
        let numb1 = document.getElementById('numb1');
        if (parseInt(e.target.innerText) >= 5) {
            numb1.insertAdjacentElement('afterend', dots);
  }
      }
} 

HTML code:

<ul id="pag">
                <li class="btn prev" id="prev"><span><i class="fas fa-angle-left">Prev</i></span></li>
                <li class="numb active" id="numb1"><span>1</span></li>
                <li class="numb"><span>2</span></li>
                <li class="numb"><span>3</span></li>
                <li class="numb"><span>4</span></li>
                <li class="numb"><span>5</span></li>
                <li class="dots"><span>...</span></li>
                <li class="numb"><span>10</span></li>
                <li class="btn next" id="next"><span>Next<i class="fas fa-angle-right"></i></span></li>
            </ul>

But for some reason when I click on 5 or 10 nothing happens, and there's an error:

Uncaught TypeError: Element.insertAdjacentElement: Argument 2 does not implement interface Element.

So I'm wondering if I have to declare "dots" in some other way or maybe the problem is in something else

about 4 years ago · Juan Pablo Isaza
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