0

I am attempting to trigger a click via jQuery while targeting a data elements. The trigger click works perfectly fine on desktop devices, however on touch devices it's failing. I was doing some reading here: jquery touchstart in browser and attempted to bind a touchstart event, but it's still not working, below is my code with and without the touchstart event.

//basic implementation that works on non-touch devices
$('.mobile-link').click(function() {
      $("[data-slidr-breadcrumbs='platforms']").trigger('click');
});

//with touchstart
var clickEventType = ((document.ontouchstart!==null)?'click':'touchstart');

$('.mobile-link').click(function() {
    $([data-slidr-breadcrumbs='platforms']).trigger(clickEventType);
});
Community
  • 1
  • 1
Andrew K
  • 147
  • 9
  • is that the attribute selector you are calling is correct?? – answer99 Jul 07 '15 at 05:28
  • The attribute selector seems to be correct since it's working on non-touch devices. Though, I wonder if the problem within touch devices stems from that somehow? – Andrew K Jul 07 '15 at 12:43

1 Answers1

-1

You want either click or touchstart events so use .on() and pass the event name as the first param

var clickEventType = ((document.ontouchstart !== null) ? 'click' : 'touchstart');

$('.mobile-link').on(clickEventType, function () {
    $("[data-slidr-breadcrumbs='platforms']").trigger('click');
});
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • Unfortunately, that's still not doing the trick, the click function fires properly - for example if I add an alert it fires upon click, the issue though, still exists from the trigger click not firing on the data attribute element. – Andrew K Jul 07 '15 at 04:18