{"id":397,"date":"2018-10-23T15:13:00","date_gmt":"2018-10-23T12:13:00","guid":{"rendered":"https:\/\/html-online.com\/articles\/?p=397"},"modified":"2020-01-14T11:28:49","modified_gmt":"2020-01-14T09:28:49","slug":"jquery-click-event-touch-devices","status":"publish","type":"post","link":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/","title":{"rendered":"Fix When jQuery Click Event Is Not Working On Touch Devices"},"content":{"rendered":"<p>You might have come across situations when the <a href=\"\/articles\/category\/jquery\/\">jQuery<\/a> click event listener works fine on desktop but it doesn&#8217;t fire on mobiles, tablets and other touch devices. This might happen when the event is not attached to an anchor tag but to some other element, like a div. There is a very simple solution to fix this issue.<br \/>\n<!--more-->This is how your original looks like in most cases.<\/p>\n<pre><span style=\"color: #687687;\">$<\/span>(<span style=\"color: #6d79de; font-weight: bold;\">document<\/span>).ready(function(){\n    <span style=\"color: #687687;\">$<\/span>(<span style=\"color: #d80800;\">\"div.clickable\"<\/span>).<span style=\"color: #3c4c72; font-weight: bold;\">click<\/span>(function(){\n        <span style=\"color: #3c4c72; font-weight: bold;\">alert<\/span>(<span style=\"color: #d80800;\">'Click'<\/span>);\n    });\n});\n<\/pre>\n<p>The correct code is below<\/p>\n<pre><span style=\"color: #687687;\">$<\/span>(<span style=\"color: #6d79de; font-weight: bold;\">document<\/span>).ready(function(){\n    <span style=\"color: #687687;\">$<\/span>(<span style=\"color: #d80800;\">\"div.clickable\"<\/span>).on(<span style=\"color: #d80800;\">'click'<\/span>, function () {\n        <span style=\"color: #3c4c72; font-weight: bold;\">alert<\/span>(<span style=\"color: #d80800;\">'Click'<\/span>);\n    });\n});\n<\/pre>\n<p>All you have to do is replace this part <strong>.click(function<\/strong> with this&nbsp;<strong>.on(&#8216;click&#8217;, function<\/strong><\/p>\n<p>I hope this simple trick helped you make your click events work on mobile and other touch devices.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might have come across situations when the jQuery click event listener works fine on desktop but it doesn&#8217;t fire on mobiles, tablets and other touch devices. This might happen when the event is not attached to an anchor tag but to some other element, like a div. There is a very simple solution to &hellip; <a href=\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fix When jQuery Click Event Is Not Working On Touch Devices&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-397","post","type-post","status-publish","format-standard","hentry","category-javascript","category-jquery"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>jQuery Click Event Not Working On Mobile And Other Touch Devices<\/title>\n<meta name=\"description\" content=\"You might have come across situations when the jQuery click event listener works on desktop but it doesn&#039;t fire on mobiles, tablets and other touch devices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"jQuery Click Event Not Working On Mobile And Other Touch Devices\" \/>\n<meta property=\"og:description\" content=\"You might have come across situations when the jQuery click event listener works on desktop but it doesn&#039;t fire on mobiles, tablets and other touch devices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\" \/>\n<meta property=\"og:site_name\" content=\"HTML Online\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/htmlcoding\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-23T12:13:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-14T09:28:49+00:00\" \/>\n<meta name=\"author\" content=\"HTML Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"HTML Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\"},\"author\":{\"name\":\"HTML Editor\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\"},\"headline\":\"Fix When jQuery Click Event Is Not Working On Touch Devices\",\"datePublished\":\"2018-10-23T12:13:00+00:00\",\"dateModified\":\"2020-01-14T09:28:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\"},\"wordCount\":120,\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"articleSection\":[\"JavaScript\",\"jQuery\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\",\"url\":\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\",\"name\":\"jQuery Click Event Not Working On Mobile And Other Touch Devices\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/#website\"},\"datePublished\":\"2018-10-23T12:13:00+00:00\",\"dateModified\":\"2020-01-14T09:28:49+00:00\",\"description\":\"You might have come across situations when the jQuery click event listener works on desktop but it doesn't fire on mobiles, tablets and other touch devices.\",\"breadcrumb\":{\"@id\":\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/html-online.com\/articles\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fix When jQuery Click Event Is Not Working On Touch Devices\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/html-online.com\/articles\/#website\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"name\":\"HTML Online Articles\",\"description\":\"Tips, tricks, tutorials\u2026\",\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/html-online.com\/articles\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/html-online.com\/articles\/#organization\",\"name\":\"HTML Online\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"contentUrl\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"width\":350,\"height\":350,\"caption\":\"HTML Online\"},\"image\":{\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/htmlcoding\/\",\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\",\"name\":\"HTML Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"caption\":\"HTML Editor\"},\"description\":\"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/@htmlg\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"jQuery Click Event Not Working On Mobile And Other Touch Devices","description":"You might have come across situations when the jQuery click event listener works on desktop but it doesn't fire on mobiles, tablets and other touch devices.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/","og_locale":"en_GB","og_type":"article","og_title":"jQuery Click Event Not Working On Mobile And Other Touch Devices","og_description":"You might have come across situations when the jQuery click event listener works on desktop but it doesn't fire on mobiles, tablets and other touch devices.","og_url":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/","og_site_name":"HTML Online","article_publisher":"https:\/\/www.facebook.com\/htmlcoding\/","article_published_time":"2018-10-23T12:13:00+00:00","article_modified_time":"2020-01-14T09:28:49+00:00","author":"HTML Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"HTML Editor","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/#article","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/"},"author":{"name":"HTML Editor","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d"},"headline":"Fix When jQuery Click Event Is Not Working On Touch Devices","datePublished":"2018-10-23T12:13:00+00:00","dateModified":"2020-01-14T09:28:49+00:00","mainEntityOfPage":{"@id":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/"},"wordCount":120,"publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"articleSection":["JavaScript","jQuery"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/","url":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/","name":"jQuery Click Event Not Working On Mobile And Other Touch Devices","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/#website"},"datePublished":"2018-10-23T12:13:00+00:00","dateModified":"2020-01-14T09:28:49+00:00","description":"You might have come across situations when the jQuery click event listener works on desktop but it doesn't fire on mobiles, tablets and other touch devices.","breadcrumb":{"@id":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/html-online.com\/articles\/jquery-click-event-touch-devices\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/html-online.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Fix When jQuery Click Event Is Not Working On Touch Devices"}]},{"@type":"WebSite","@id":"https:\/\/html-online.com\/articles\/#website","url":"https:\/\/html-online.com\/articles\/","name":"HTML Online Articles","description":"Tips, tricks, tutorials\u2026","publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/html-online.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/html-online.com\/articles\/#organization","name":"HTML Online","url":"https:\/\/html-online.com\/articles\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/","url":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","contentUrl":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","width":350,"height":350,"caption":"HTML Online"},"image":{"@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/htmlcoding\/","https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww"]},{"@type":"Person","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d","name":"HTML Editor","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","caption":"HTML Editor"},"description":"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.","sameAs":["https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/@htmlg"]}]}},"_links":{"self":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/comments?post=397"}],"version-history":[{"count":4,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/397\/revisions"}],"predecessor-version":[{"id":1165,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/397\/revisions\/1165"}],"wp:attachment":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/media?parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/categories?post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/tags?post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}