I have an issue that requires an albeit strange workaround. Essentially, I have a menu on a tablet that needs to ignore the user clicking/selecting the link the first time, but once selected the second time, it then executes the link.
So say we have a link here that goes to Google: Google.com
How can I stop the window from loading the link until it's clicked a second time? This is so multiple menu items can be clicked if they have children to show the submenus.
I've looked around and all I've found is event.stopImmediatePropagation();
But this ignores all click events entirely, which is not what I need.
Is it possible to do this? There should be a way to detect click count, surely?
I would make a globally accessible counter variable and then make an if statement around what you want to run inside that click function so that it only executes when you want. Ex:
Hope that helps!
One way to achieve the requirement is to use data attributes.
When user clicks the link, check if the data attribute (let's say 'data-clicked-once') exists on that link element. If not, setup this attribute to 'true'. If the attribute exists, execute the code for showing the menu.
Note that when you get attributes from .attr() it always returns string
you could try adding a variable to detect if it has been clicked yet:
then when it is clicked:
You can check for a class say,
.clicked
, if found follow the link, if not found -- that must be the first click -- do not follow the link, add the classclicked
:DEMO
You can use something similar to this :
Fiddle