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

217
Views
Why is this eventListener firing twice upon button click?

I am very new to front end development and recently started setting EventListeners for my HTML elements with JS opposed to adding an onclick html tag as I was told onclick is bad practice (is that true?)

In the below code, the phrase that I log in the console ("Test, the input tag was clicked") always logs twice every time an input is clicked. TThe event should of course only fire once and I have no idea it prints in the console twice, what am I doing wrong?

(function () {
    window.addEventListener("load", () => {
        const documentParentElement = document.querySelectorAll(".rating-button");

        documentParentElement.forEach(element => {
            element.addEventListener("click", event => {
              const targetElement = event.target;
              console.log("Test, the input tag was clicked")
              const selectedRating = targetElement.value;
            })
        });
    });
}());
<div class="rating" data-decision-id="{{decision.id}}" data-user-id="{{decision.user_id}}">
        <input type="radio" class="rating-button" id="star-1-{{decision.id}}" name="rating" {% if decision.rating.rating == 1 %} checked {% endif %} value="1"/>
        <input type="radio" class="rating-button" id="star-2-{{decision.id}}" name="rating" {% if decision.rating.rating == 2 %} checked {% endif %} value="2"/>
        <input type="radio" class="rating-button" id="star-3-{{decision.id}}" name="rating" {% if decision.rating.rating == 3 %} checked {% endif %} value="3"/>
        <input type="radio" class="rating-button" id="star-4-{{decision.id}}" name="rating" {% if decision.rating.rating == 4 %} checked {% endif %} value="4"/>
        <input type="radio" class="rating-button" id="star-5-{{decision.id}}" name="rating" {% if decision.rating.rating == 5 %} checked {% endif %} value="5"/>     
</div>

about 4 years ago · Juan Pablo Isaza
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!