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

223
Views
I'm studying Javascript and my addeventlistener is not working on onClick

I'm coding a simple app to add itens to a shopping bag to study Javascript. However my js code didn't register when the element is clicked, it's not printing on console.

window.onload = function() {
    //your code here
    const fruitList = [{
            'fruit': 'Banana',
            'price': 3.9
        },
        {
            'fruit': 'Orange',
            'price': 0.7
        },

    ]

    const product = document.getElementById('products')
    ListaFrutas.map((n) => {
        product.insertAdjacentHTML('afterbegin', '<li class="fruits">' + n.fruit + '</li>');
    })

    const shoppingBag = []
    const fruitproduct = document.querySelector('.fruits')
    fruitproduct.addEventListener("onClick", handlerClick)

    function handlerClick() {
        console.log('it works')
    }
}
<div id="content-produtos" class="flex" >
  <ul id="produtos" >
  </ul>
</div>

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

0

Assuming LitsaFrutas is defined elsewhere, you should replace "onClick" with "click".

addEventListener("click", handlerClick);

See also: Difference between "click" and onclick

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!