Need help with long-press-event?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

219 Stars 69 Forks MIT License 57 Commits 7 Opened issues


Adds `long-press` event to the DOM in 1k of pure JavaScript

Services available


Need anything else?

Contributors list


Shippable branch npm

A 1k script that adds a

event to the DOM using CustomEvent and pure JavaScript. Works in IE9+, Chrome, Firefox, Safari as well as popular mobile browsers including Cordova (Phone Gap) applications.

Defaults to 1.5 seconds but can be overridden by adding a

attribute to an element.

Try the demo


Add the long-press-event.min.js file to your page and then listen for the event.

To listen for a

on any HTML element:
// the event bubbles, so you can listen at the root level
document.addEventListener('long-press', function(e) {

To listen for a

on a specific HTML element:
// grab the element
var el = document.getElementById('idOfElement');

// listen for the long-press event el.addEventListener('long-press', function(e) {

// stop the event from bubbling up e.preventDefault()

console.log(; });

To set a custom delay and listen for a

    <script src="long-press-event.js"></script>
        document.addEventListener('long-press', function(e) {

    <div data-long-press-delay="500">Press and hold me for .5s</div>

To set a default application wide

, set attribute on a parent/topmost element:


  1. Fork it!
  2. Create your feature branch:
    git checkout -b my-new-feature
  3. Commit your changes:
    git commit -m 'Add some feature'
  4. Push to the branch:
    git push origin my-new-feature
  5. Submit a pull request


The project includes everything needed to tweak, including a node webserver. Run the following, then visit http://localhost:8080 in your browser.

You can test on a desktop using Device Mode in Google Chrome.

git clone
cd long-press
npm install
npm start

Update .min files

Update long-press-event.min.js by tweaking the version number in

and running:
npm run build

Star the repo

If you find this useful, please star the repo. It helps me prioritise which open source issues to tackle first.


For change-log, check releases.


Licensed under MIT License © John Doherty

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.