1

I tried a whole bunch of things from:
onClick not working on mobile (touch)

document .click function for touch device

However nothing seems to work.

Here's what I have:

#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();
            })
        });

What might I be doing wrong?

Community
  • 1
  • 1
blue_zinc
  • 2,410
  • 4
  • 30
  • 38

2 Answers2

0

Change the id of your button to modal_close. This may work for you. The id value acts like an identifier, so there is rule that we cannot use every symbol for naming identifiers.

-1

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.

blue_zinc
  • 2,410
  • 4
  • 30
  • 38