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

122
Views
different ways in javascript of adding Event Listener to browser DOM

In javascript what are the different ways of adding an event listener to browser DOM? i have tried the following code, and i was wondering if there are more ways to do this.

let div = document.getElementById("div");
let btn = document.getElementById("btn");

function sayHello() {
    div.innerText = "Hello World";
    console.log("awesome");
}

btn.addEventListener("click", sayHello);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In JavaScript, there are two ways for event handling.

  • One of them is addEventListener that you used yourself.
  • Another option is onEvent, here is an example:

Javascript

let hiButton = document.getElementById('someButton');

function sayHello() {
    console.log("Hi");
}

hiButton.onclick = sayHello();
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!