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

247
Views
Why can't I add an event listener using Webpack module?

I'm new to Webpack & node, so bear with me. I'm trying to create global event listeners on the Document Body and run functions as they change / click, etc. My problem is the event listeners are not attaching to the document. I can inspect the body and none of the event listeners are attaching. What am I doing wrong?

  • The file is loading properly
  • I'm getting an error: e is undefined when the validateProductAttribues(e) function is run.
  • I tried moving the Click and Change event listeners into the DOMContentLoaded listener, but that didn't work.

I'm trying to organize my code like so:

Product.js

import { validateProductAttributes, resetProductAttributes } from "./product-functions";


function runClickEvents(e) {
  resetProductAttributes(e);
}

/**
 * ======= CHANGE EVENT =========
 */
function runChangeEvents(e) {
  if (e.target.id.includes("pa_")) {
    showAddOnsMessage();
    validateProductAttributes(e);
  }
}

// Run Load Events
document.addEventListener("DOMContentLoaded", runLoadEvents);
// Run Click Events
document.body.addEventListener("click", (e) => runClickEvents);
// Run Change Events
document.body.addEventListener("change", (e) => runChangeEvents);

// Adds class of Validated to select box when an option is selected
export function validateProductAttributes(e) {
  e.target.value !== "" ? e.target.classList.add("validated") : e.target.classList.remove("validated");
}

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!