0

This is the javascript I use for my burger navigation. My code works perfectly on Chrome, but it doesn't works on my iPhone. I think it has to do with the "click" but i'm not sure.

I tried using "touchend" instead of click but that doesn't work either.

This is my code:

onload = function() {
    var hetMenu = document.querySelector("body > header nav");
    hetMenu.addEventListener("click", menuToggle);
}

function menuToggle() {
    var deBody = document.querySelector("body");
    deBody.classList.toggle("navigatie");
    console.log(deBody.classList);
}
strah
  • 6,702
  • 4
  • 33
  • 45
Sebastiaan
  • 105
  • 2
  • 10
  • Have you checked if `menuToggle` function is called after the click? Is it possible that on small screen something covers the element click event is attached to? – strah Nov 02 '14 at 11:32
  • No I think that's not it. When I downsize my Chrome screen to mobile format it works just fine. – Sebastiaan Nov 02 '14 at 11:42
  • Check if: **1.** `menuToggle` is being called after click, **2.** manually add `navigate` class to your `body` element and see if that works on the device – strah Nov 02 '14 at 11:54

2 Answers2

1

Use both click and touchstart events.

See: onClick not working on mobile (touch)

It's jQuery but same events can be used.

ThdK
  • 9,916
  • 23
  • 74
  • 101
KyleK
  • 4,643
  • 17
  • 33
0

You can use 'touchstart' with jquery.

$('#button1').on('touchstart click', function(){ /* code here */ });

karmafunk
  • 1,453
  • 12
  • 20