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

124
Views
Find what happens when you click an HTML button

For example, you have this script that adds an event listener to a button like this:

document.getElementById("myBtn").addEventListener("click", function() {
  document.getElementById("demo").innerHTML = "Hello World";
});

How would I see that code in a website, so I can execute the code from the console?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You want to trigger the event from the console. But that is not possible. However, you can call an external function in the second parameter of the EventListener. This function is then in the global scope. You can then trigger the action in the console with the function name that would otherwise be triggered via the click.

makeAction();

document.getElementById("myBtn").addEventListener("click", function() {
  makeAction();
});

function makeAction() {
  console.log('triggered')
  document.getElementById("demo").innerHTML = "Hello World";
}
<button id="myBtn">click</buton>
<div id="demo"></div>

about 4 years ago · Juan Pablo Isaza Report

0

On Chrome, you can open developer tools, select the element, then select the 'Event Listeners' tab:

enter image description here

Which will show you the event listeners bound to the element:

enter image description here

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!