Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:19:31+00:00 2026-06-12T09:19:31+00:00

Some Quick Background I’m building an iOS app that uses html web views in

  • 0

Some Quick Background

I’m building an iOS app that uses html web views in some areas. I wanted to make sure the html buttons on those pages looked and felt as much like iOS buttons as possible. To accomplish this, I wanted a tap state so the html button depressed when tapped. Now in HTML this is easy. You just set a style for :active or :hover or whatever. I actually had this defined already. In iOS, however, those states don’t engage on tap – at least normally. So my goal was to write a little script that added a class to the button to change its appearance ontouchstart.

The Issue

However, it turns out I didn’t need to get that complicated…by pure accident I ran a test with the following code:

document.addEventListener('touchstart', function(event) {
    console.log("test");
}, true);

I’m pretty green with javascript & jQuery, so all I intended on doing was checking my syntax and making sure the eventListener fired when I tapped the button. To my surprise, the button’s :active states in the css fired (as well as the :hover states). That code…solved my problem!

My Question

So here’s my question: Is the above code valid? I mean, is it bad to do this? It’s as if the empty eventListener just triggered behavior that desktop browsers already offer. Is there anything wrong with using this method? I’m green, but I don’t want to pick up bad habits. If this is a bad way to code I don’t want to use it.

Thanks for any insight you guys can give me into this!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:19:32+00:00Added an answer on June 12, 2026 at 9:19 am

    I personally don’t think anything’s wrong with empty event listeners (save for the overhead of a function call — which sounds negligible here anyway). I’d suggest you leverage jQuery’s noop function though if you must add an event listener but have it do nothing:

    $(document).on('touchstart', $.noop);
    
    // or
    
    document.addEventListener('touchstart', $.noop);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background In Java, I want to make a simple, quick console app that provides
Some quick background on my problem: I'm writing a compiler that converts Domain Type
Quick background I have a concurrent map I used to cache some values that
this is my first question on stack overflow. Some quick background, this is not
Just need some quick clarification I have 2 Queries in my Access Database that
Background This is only my second PyQt4 project. Developing a Windows app that has
Quick question: Will KnockoutJS provide a solid ground for developing a large web app?
The quick overview is this: for my web app I can write most of
Background: I've got a web app on sub.domain.com. My primary website is on domain.com.
Some quick background on what I'm working on: I've got a page with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.