<a> tag does not respond to on("click") event in some touch devices

Viewed 53

I have <a> tag that doesn't have (href) attribute. It doesn't respond to on("click") event when the client click (touch) it in some touch devices, but it works with the other devices also it works in chrome developers tools!

HTML code:

<a class="completeTask c hidden" data-id="{{todo[0]}}"><i class="fas fa-check"></i></a>

Javascript code ( using event delegation in jQuery ):

$(".tasks").on("click", ".completeTask", function() {}

What should I add to make it works?

1 Answers

Try this! Just vanilla Js! No Jquery needed! This should work on touch devices.

function redirect() {
  //Replace stackoverflow wit real URL
  window.location.replace("stackoverflow.com")
}
/* optional */

a {
 color: red;
 }
 
 a:hover {
 color: crimson;
}

a:visited {
color: orangered;
}

/* optional */
<a onclick="redirect()">example link</a>

Related