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

218
Views
How to tell where my JavaScript click event is being canceled

I'm working on a Shopify project and am not the original developer, who is unavailable, along with an un-minified version of the javascript file included on every page.

The original site has a page displaying a grid of employee headshots. I have been tasked with enhancing by making it such that each headshot has an overlay that displays some additional info and that clicking on either the headshot image OR the overlay (and its contents) will take some additional action.

Each grid item (headshot) essentially looks like this:

<div class="wrap">
  <img src="PATH_TO_IMG">
  <div class="info">Danny Testeroni</div>
</div>

and my event listener/handler looks like this:

const $item = document.querySelector('.wrap');
$item.addEventListener('click', (e) => {
  console.log(e.target);
});

All works as expected.

Clicking anywhere within the grid item, console.logs the image UNLESS you click anywhere on the overlay, in which case, it console.logs the overlay container. This is what I need.

However when I add this to the actual Shopify template (in which this global JavaScript file gets included), i get different results.

Clicking anywhere within the grid item, console.logs the image UNLESS you click anywhere on the overlay, in which case, it console.logs NOTHING.

The only thing I can conclude is that something in the global JavaScript file is canceling the click event at the <img> so it never makes it to the overlay. Is this the case? If so, is there any way to tell where this is happening and possibly overriding it with my new script? And if not, any ideas why clicks on the overlay may not be registering in the actual Shop as opposed to my bare bones prototype, which can be seen in this Codepen?

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

0

You can remove the arrow function on your addEventListener handle and use this, to reference the element it was attached to

const $item = document.querySelector('.wrap');
$item.addEventListener('click', function(e) {
  console.log(this);
})
<div class="wrap">
  <img src="https://cdn.shopify.com/s/files/1/0598/3089/4765/articles/barber-culture_x700.png?v=1646319227">
  <div class="info">Danny Testeroni</div>
</div>

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!