Search code examples
jquerymobileevent-handlingmobile-website

Jquery Mobile - pagebeforehide - can't get event to fire


I'm trying to fire an event in JqueryMobile when navigating within a multipage. I can't get the event to fire. Anybody can help?

<div data-role="page" id="mainPage">
    <div data-role="content">
            <p>Content</p>
            <p>View internal page called <a href="#2ndPage">2ndPage</a></p>
    </div>   
</div>

<div data-role="page" id="2ndPage">
    <div data-role="content">
            <p>SubContent</p>
            <p><a href="#mainPage">MainPage</a></p>
    </div>
</div>

And my script:

$('#mainPage').bind('pagebeforehide', function (event, ui)
             {
             alert ("leaving MainPage");
             });

Thanks for helping!

Frequent


Solution

  • you should use "live" instead of "bind"

    $('#mainPage').live('pagebeforehide', function (event, ui)
    {
        alert ("leaving MainPage");
    });