gurehbgui
gurehbgui

Reputation: 14684

why my pageinit is not triggered in jquery-mobile-1.3.2

I have a problem with my JqueryMobile page. I get the pageInit event when I navigate to page2 but when I start the site (on page1) I dont get any event. How to fix this issue?

Here is my html code:

<body>
    <!-- Home -->
    <div data-role="page" id="page1">
        <div data-role="content">
            ...
        </div>
    </div>

    <!-- Page2 -->
    <div data-role="page" id="page2">
        <div data-role="content">
            ...
        </div>
    </div>
</body>

javascript file:

$(document).bind('pageinit', function () {
    $('#page1').bind("pageinit", function () {
        alert("1");
    });

    $('#page2').bind("pageinit", function () {
        alert("2");
    });
});

Upvotes: 0

Views: 214

Answers (2)

Kiran
Kiran

Reputation: 20313

Try:

$(document).on('pageinit', '#page1', function() {      
    alert('Page main initialized');
});

$(document).on('pageinit', '#page2', function() {      
    alert('Page two initialized');
});

Upvotes: 1

Asso
Asso

Reputation: 47

Why do you need to bind init twice ?

Try with :

$('#page1').on("pageinit", function () {
    alert("1");
});

$('#page2').on("pageinit", function () {
    alert("2");
});

So I'm Removing the document binding.

Upvotes: 1

Related Questions