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

144
Views
How are the objects created and triggerd internally

How exactly is JS triggering the button's onclick function even before its been clicked during page load?

P.S:I come from PYTHON background

var btn = document.getElementById("btn")

// this works fine (alert box appears when clicked)

btn.onclick = function(){
    alert('clicked')
}

// this shows alert box when the page loads when clearly onclick is mentioned

function foo(){
    alert('clickedd')
}
btn.onclick = foo()

This is for the simple HTML button inside a form table.

about 4 years ago · Santiago Trujillo
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!