Onclick Not Working on Mobile (Touch)

plain javascript, onclick not working on mobile

Try to change onclick to addEventListener and see if that helps you..

// When the user clicks the button, open the modal btn.addEventListener('click', function () {    var x = window.innerWidth;    if (x > 768) {        //event.preventDefault();        modal.style.display = "block";    } else {        //event.preventDefault();    }});

onClick not working on mobile (touch)

better to use touchstart event with .on() jQuery method:

$(window).load(function() { // better to use $(document).ready(function(){
$('.List li').on('click touchstart', function() {
$('.Div').slideDown('500');
});
});

And i don't understand why you are using $(window).load() method because it waits for everything on a page to be loaded, this tend to be slow, while you can use $(document).ready() method which does not wait for each element on the page to be loaded first.

jQuery onclick not working on mobile

<script type="text/javascript">
$(document).ready(function(){
$('#mobileMenuButton').on('mousedown touchstart',function(){
var userAgent = window.navigator.userAgent;
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)|| userAgent.match(/Android/i)) {
if ($('#mobileNavigation').css('display') == 'none') {
$('#mobileNavigation').css('display','block');
} else {
$('#mobileNavigation').css('display','none');
}
}
});
});
</script>

Just provide the user agent.

Button onClick not working on mobile device

Turned out

 #modal-close {cursor:pointer;}

<button class="button" id="modal-close">ok</button>

function hideModal(){
var modal = document.getElementById('modal');
modal.style.display = 'none';
}

$(function() {
$('#modal-close').on('click touchstart',function (e) {
hideModal();
})
});

Was valid

The thing that got me was hideModal() which used classList to add or remove classes. I switched it to className += and it worked as supposed to.

JavaScript onclick event not working on mobile device

The Ajax was failing due to the www. missing from the website URL.

Click event not working in mobile

There was another function that was manipulating the links, I just reapplied the click method afterwards.

Does HTML's 'onclick' work on mobile devices?

Yes it will work.

This has been answered here: Would onClick event work on touch on touch-screen devices?

See https://www.w3schools.com/tags/ev_onclick.asp for browser support



Related Topics



Leave a reply



Submit