Page 2 of 2
Re: Can Javascript disable HREF's first click?
Posted: Fri Feb 03, 2017 6:19 am
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.
Re: Can Javascript disable HREF's first click?
Posted: Fri Feb 03, 2017 6:26 am
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).
Re: Can Javascript disable HREF's first click?
Posted: Fri Feb 03, 2017 6:28 am
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.
Re: Can Javascript disable HREF's first click?
Posted: Fri Feb 03, 2017 6:48 am
by requinix
Take a read through
MDN's event guide. In the meantime I need to eat.
Re: Can Javascript disable HREF's first click?
Posted: Fri Feb 03, 2017 7:59 am
by requinix