Can Javascript disable HREF's first click?

JavaScript and client side scripting.

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can Javascript disable HREF's first click?

Post by simonmlewis »

I'm learning as I go with this sort of stuff.
I don't know how to add a "touchstart event listener".
:hover works on some mobiles, as it adapts to use it via a tap, except Android. Tho logically, it shouldn't work on mobile at all.
So how do I code what you have described?
As you can see, this is needed for the main dropdown, but also the Category dropdowns too.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Can Javascript disable HREF's first click?

Post by requinix »

Main, category, works the same way.

No Javascript framework means you'll have to do this all manually, which sucks. Consider using one.

Start by finding all the menu elements that you'll want to expand. querySelectorAll should get you pretty far.
Then for each element in the list that it returns you use addEventListener with touchstart

Code: Select all

.addEventListener("touchstart", function(e) {
Inside that callback function you'll have "this" as whatever element. Apply the logic I said to switch class names, and if you need to remove it from other menu items (recommended) then querySelector can find you the currently open menu (if there is one).
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can Javascript disable HREF's first click?

Post by simonmlewis »

Can you show me a short 'fiddle' version of what you are getting at?
I've looked at that page, but I no zero about that sort of code, so to do the rest of what you have described, it's not in my power!

If I see an example, I can get my head around it, and see what's what.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Can Javascript disable HREF's first click?

Post by requinix »

Take a read through MDN's event guide. In the meantime I need to eat.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Can Javascript disable HREF's first click?

Post by requinix »

Post Reply