Reputation: 45
So I'm basically making a grid where a single click is a circle and a double click is a square. However, if I go back to an already clicked box and make a single or double click, it changes the shape in it. Is there a way to make an already clicked box not clickable anymore?
Upvotes: 2
Views: 874
Reputation: 41
I believe setting the CSS property 'pointer-events' to 'none' should work.
pointer-events: none;
Upvotes: 3
Reputation: 669
This should work
https://codesandbox.io/s/vn96m0o6l
Problem is that double click is still click. So it first triggers click handler than double click. That is why i set timeout of 200ms on click handler.
Double click handler also passes isDoubleClick flag so that handler knows what to do. And in handler based on that and class not existing yet decides which action to do. When click handler gets activated, element already has class and just ignores it.
Could be better, but will fix problem
Upvotes: 2
Reputation: 1488
Just add A variable after click and use this
if (isClicked = 1){
$(this).unbind("click");
}
or use vanilla js like this
document.getElementById("myElement").onclick = function() { return false; }
Upvotes: 1