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
Document.All VS. Document.Getelementbyid
How to Query Referenced Objects in Mongodb
Why Does a String Index in an Array Not Increase the 'Length'
Determine Pixel Length of String in JavaScript/Jquery
Accessing Variables from Greasemonkey to Page & Vice Versa
Precise Financial Calculation in JavaScript. What Are the Gotchas
JavaScript How to Parse JSON Array
How Does the Math.Max.Apply() Work
How to Refresh an Iframe Using JavaScript
How to Get a Url Parameter in Express
How to Create a Jquery Function (A New Jquery Method or Plugin)
Moment Js Date Time Comparison
How to Find the Height of Text on an HTML Canvas
(1, Eval)('This') VS Eval('This') in JavaScript
Using _ (Underscore) Variable with Arrow Functions in Es6/Typescript
iPad Web App: Detect Virtual Keyboard Using JavaScript in Safari