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

107
Views
Touch events not triggered on element edges in iOS Safari

On touch devices the following events are triggered when touching an element:

  • touchstart
  • touchend
  • mouseenter
  • mousedown
  • mouseup
  • click

The mouseenter, mousedown, mouseup and click events are emulated by the touchend event. If you want to disable this emulation of mouse events, preventDefault() can be used.

But if in iOS Safari I touch the edges of an element the following events are triggered:

  • mouseenter
  • mousedown
  • mouseup
  • click

Somehow the touch events are not triggered on the edges and because of this I also can't use preventDefault() to stop the emulation of the mouse events.

The problem occurs on both iPhone as iPad.

I searched Stack Overflow and Google, but I can't find anything about this. No bugs and no solutions. Does anybody know if this is a known bug in Safari?

I created the most basic code to reproduce this error in JSFiddle:

HTML:

<div id="element"></div>
<div id="log"></div>

CSS:

#element {
  height: 100px;
  width: 100px;
  background: yellow;
  margin: 20px;
}

JavaScript:

function handler(event) {
  const log = document.getElementById('log');
  
  log.innerHTML = `${event.type}<br />${log.innerHTML}`;
}

const element = document.getElementById('element');

element.addEventListener('mouseenter', handler);
element.addEventListener('mouseleave', handler);
element.addEventListener('mousedown', handler);
element.addEventListener('mouseup', handler);
element.addEventListener('click', handler);
element.addEventListener('focus', handler);
element.addEventListener('blur', handler);
element.addEventListener('touchstart', handler);
element.addEventListener('touchend', handler);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try attaching the event listener to the outermost element, the html tag.

See more: https://www.tutorialrepublic.com/javascript-tutorial/javascript-event-propagation.php

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!