David_Hogan
David_Hogan

Reputation: 125

jQuery onclick not working iOS 10 <a> Tag

I've got a slow loading link on a page so I wrote the below javascript that triggers a loading message. The problem is its not working on mobile devices. I've tried using touchstart touch etc but when the link is tapped it triggers the loading screen but does not load the URL. I've also tried adding style="cursor:pointer;" to the with no success.

An example link would be:

<a href="http://google.com">Example Link</a>

$(document).ready(function () {
  $("a").on('click', function () {
     $('add stuff to js body').prependTo(document.body);
  });
});

JSFiddle

Upvotes: 0

Views: 123

Answers (1)

Harsh Doshi
Harsh Doshi

Reputation: 96

Please try this code.I hope it will help you.

<a href="http://google.com">Example Link</a>

<script>
$(document).ready(function () {
  $("a").on('click', function (e) {
    e.preventDefault();
    //do your stuff
    window.location.href = $(this).attr('href');
  });
});
</script>

Thank You.

Upvotes: 1

Related Questions