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.
Can Javascript disable HREF's first click?
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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Can Javascript disable HREF's first click?
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
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).
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) {-
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?
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.
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.
All the best from the United Kingdom.
Re: Can Javascript disable HREF's first click?
Take a read through MDN's event guide. In the meantime I need to eat.