Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!