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

240
Vistas
Why does the function run once when I put this.onclick=' ';?
<a href="#" onclick="addP(); this.onclick='';">See more</a>    

Why does the function run once when I put this.onclick=' ';?

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

0

When you clicked the link.

  1. It calls addP.
  2. It removes onclick handler.

Now the actual HTML looks like

<a href="#" onclick="addP();">See more</a> 

To fix this remove onclick='' part in the onclick attribute.

let addP = () => alert('you clicked the link')
<a href="#" onclick="addP();">See more</a>    

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to remove this.onclick=''; because when the o'clock event (addP) Is over, it removes the the click event handler. So there are 2 methods for you :


Method 1
use javascript & html like so :

HTML :

<a href="#" id="seeMore">See more</a>    

Javascript :

document.getElementById('seeMore').addEventListener('click', function() {
    addP();
});


Method 2
only using html

<a href="#" onclick="addP();">See more</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