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 6528423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:31:59+00:00 2026-05-25T09:31:59+00:00

I think that focus event doesn’t work with JQuery mobile: here is my code.

  • 0

I think that focus event doesn’t work with JQuery mobile: here is my code. (when I delete the call to the library jquery mobile, it works)

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
        <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
    </head>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#acceuil').live('pagecreate', function(event) {
                $('#declencher').click(function() {
                    $('#cache').focus();
                });
                $('#declencher').trigger('click');
            });
        });
    </script>
    <body>
        <div data-role="page" id ="acceuil" >
            <div data-role="header" data-theme="a" ><h3>aaa</h3></div>
            <div data-role="content">
                <input id="cache" type="input">    
                <input type="button" id="declencher" value="declencher">
            </div><!-- content-->
            <div data-role="footer" data-theme="a" data-position="fixed"><h3> Footer </h3></div>
        </div>
    </body>

</html>
  • 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-05-25T09:31:59+00:00Added an answer on May 25, 2026 at 9:31 am

    pagecreate event fires before JQM does some changes to DOM so I suppose the focus is lost then.

    Try switching to pageshow, especially because you want to get the focus everytime user gets to a page.

    If it still doesn’t work (there was such a case) wrap the code that triggers focus in a timeout (yes, it’s a hack 🙂 )

    setTimeout(function(){
     $('#cache').focus();
    },0);
    

    This is a hack, but it does not depend on waiting a time interval. setTimeout() adds the function to rendering thread’s queue (which is what runs javascript and page rendering in the browser) after the given time. So in this case the function is added instantly, so it runs after the current flow of javascript code finishes. So it’s a way to make some code run right after the event handler ends. So this is not as hacky as one might think. I call it a hack, because it’s using knowledge about how the browser works and it obscures the flow of code execution.

    I recommend reading about how javascript execution and page drawing are handled by the same queue in a single thread. To anybody working with more than 20 lines of javascript.

    I am quite sure that there is only one better solution – fix it in jQuery Mobile framework itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to attach a simple focus/blur event listener via the .live() jQuery method
I have a bug in my code that made me think I don't fully
I think that java executables (jar files) are trivial to decompile and get the
I think that business logic should exist in a model when using an MVC
I think that it used to the be the case that in Liferay 4,
just think that when I opened my file then when I want to write
I think that this problem can be sorted using reflection (a technology which I'm
I think that Visual Studio's biggest let down is the Javascript editor. I have
I think that the zipper is a beautiful idea; it elegantly provides a way
Do you think that writing about software (i.e. having a blog) and speaking on

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.