79432007

Date: 2025-02-12 05:12:52
Score: 0.5
Natty:
Report link

Select them into a single variable using querySelectorAll and then give single addEventListener using loop.

const divs = document.querySelectorAll("#div-1, #div-2");

divs.forEach(function(div) {
    div.addEventListener("click", function() {
        console.log("Div clicked!");
    });
});
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: e.saleh