Search code examples
jquerycordovajquery-mobilemobile-application

jQuery mobile mobileinit not triggered


I want to load the page content dynamically through AJAX before the jQuery mobile gets loaded so I am trying to use the mobileinit event. But it is not working. here is my code please help

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="http://jquerymobile.com/demos/1.3.0-beta.1/css/themes/default/jquery.mobile-1.3.0-beta.1.css" />
    <script src="js/jquery-1.8.2.min.js"></script>
    <script>
        $(document).bind("mobileinit", function()  {        
            $("#notification").text("Please enter your domain name.");
        });
    </script>
    <script src="js/jquery.mobile-1.3.0.min.js"></script>
    <title>Insert title here</title>
    </head>
    <body>
       <h3 id="notification" style="font-family: fantasy; color: red; text-align: center;"></h3>
    </body>
    </html>

Solution

  • This will not work.

    DOM content is still empty when mobileinit event is triggred. Pageinit is a first event where you can even think about doing this. But much better one is a pagebeforeshow event.

    $(document).on('pagebeforeshow', '#index', function(){    
    
    });
    

    Here's my old example of adding dynamically generated content: http://jsfiddle.net/Gajotres/GnB3t/

    And here's another example, just click next button to see a dynamically generated page: http://jsfiddle.net/Gajotres/8jcGb/