0

I'm working on this website and I don't currently know how to test this on iOS for free. I'm trying JavaScript out. Should this function? Sorry, I think I'm still a little new. Thanks

            const navbarElement = document.querySelectorAll('.navbar .subnav #raiseup img.catalogue-img');

            navbarElement.addEventListener('touchstart', function(e) {
              e.preventDefault(); // Prevents the default touch behavior
              this.classList.toggle('hovered');
            });

            // Optional: Remove the class on touchend or touchcancel
            navbarElement.addEventListener('touchend', function() {
              this.classList.remove('hovered');
            });

            navbarElement.addEventListener('touchcancel', function() {
                this.classList.remove('hovered');
            });
0

1 Answer 1

0

You're trying to add touch event listeners to a list of elements (querySelectorAll), not individual elements.

Use a forEach loop to add the listeners to each element found by querySelectorAll.

For testing on IOS, if you have a computer running MacOS, you can enable the develop menu in safari's preferences.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.