disable "click" for a limited time

94 views Asked by At

I made a simple Java Script game where you can flip cards and look for a match. Much resembling "Memory". My problem is when I click the elements (cards) you can still click the other elements (cards) therefore being able to flip more than 2 cards at a time, which would be cheating. I do have in place a setTimeout function that will automatically flip the cards all back over when the time runs out (after 2 cards have been flipped). Is there a way I could disable the clicking of the elements (cards) during the duration of the setTimeout and then re-allow the clicking after.

I tried $('body').on('click',(false)); cause I figured if you couldn't click on anything that would work just the same, but it doesn't stop any clicks.

My code runs like this $("#Card1").on('click', function(){and each card is in a div (so that way the image is clickable).

Also please excuse any mistakes I've made here, I'm a bit of a novice and new to posting on forms.

1

There are 1 answers

1
GavinBrelstaff On

Try this:

$("#Card1").off('click');