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

  • Home
  • SEARCH
  • 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 8310515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:29:12+00:00 2026-06-08T19:29:12+00:00

When I create a div in HTML code ant then bind touch event on

  • 0

When I create a div in HTML code ant then bind touch event on it – everythig going perfect. But when I create div like that: $('<div ...></div>') then binded touch events wont work. Same behaviour are on iPad and Android devices.

Here is a code to reproduce an issue:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="libs/jquery-1.7.2.js"></script>
    <script language="JavaScript">
        $(function() {
            $('#a').bind('touchstart', function(e) { alert('It works!'); });

            var b = $('<div style="width:100px; height:100px; background-color:red;" id="b" ></div>');
            b.bind('touchstart', function(e) { alert('Does not work :-('); });
            $('body').append(b);
        });
    </script>
</head>
<body>
    <div style="width:100px; height:100px; background-color:green;" id="a" ></div>​
</body>

Example at jsfiddle: http://jsfiddle.net/EqJDA/11/

I was searching around and noticed that if you bind any mouse event and touch event on same element then touch event will be ignored. I’ve thought that jQuery added some hidden mouse events and listed all them for the div “b” but there was only one touch event.

UPDATE: if events binded after element appended to DOM – everythig works good. But I cant predict when element will be appended to DOM and must construct it and add events before it happens.

So, does anyone know why this happens? Is there any workarounds?
Thanks.

  • 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-08T19:29:13+00:00Added an answer on June 8, 2026 at 7:29 pm

    what i think after going through your code is you have not appended the element in the DOM. So the event is not getting registered.

    try this.

    $(function() {
                $('#a').bind('touchstart', function(e) { alert('It works!'); });
    
                var b = $('<div style="width:100px; height:100px; background-color:red;" id="b" ></div>');
    
                $('body').append(b);
    b.bind('touchstart', function(e) { alert('Does not work :-('); });
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes I need to use the same html code in different templates, like: <div
I'm trying to create a div in HTML and then in a separate style
I'm busy writing a servlet that generates HTML code. The goal is to create
I need to insert html code like this in my zend form: <div class=myClass1
I have the following html code: (that gets loaded via ajax into a div)
I want create a plugin in jquery. this is my html code : <div
I'm trying to create a small html fragment (a div element) consisted of three
What CSS is needed to create such an HTML layout: +--[li]---------------------------------------------+ |+--[div]-------------------------------------++---+| || A
In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
I have created a simple layout using the HTML div tag. I would like

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.