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

349
Vistas
Prevent reload page when click on button take you to the same page link?

I would like to prevent an HTML button that acts like a link take you to the same page from reload the page

For Example: prevent reload the website when click on logo if you are in Homepage.

How can I do this?

Full code: https://codepen.io/Muh-Ail/pen/oNpLKXM?editors=0010

   let activeBtn = document.querySelector(".active-btn");
   let currentLocation = location.href;

    if (activeBtn.href === currentLocation) {

        activeBtn.preventDefault();

    }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use this instead

let activeBtn = document.querySelector(".active-btn");
let currentLocation = location.href;


if (activeBtn.href === currentLocation) {
    activeBtn.addEventListener('click',function(e){
        e.preventDefault();
    });
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You'd have to use the e.preventDefault(); from the listener ele.addEventListener("click", function (e) instead;

Also, you should wrap the js with:

document.addEventListener("DOMContentLoaded", () => {
// code here
});

You should add different links for you to be able to see.

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