MikeMurko
MikeMurko

Reputation: 2233

Persistent HTML outside of jQuery Mobile Pages

I want to include a bit of HTML outside of the <div data-role="page"> element on my main page. This HTML shouldn't be replaced when a new page is loaded in via ajax.

The example application for this is to have a small absolutely positioned div in the top-right that is only displayed upon errors related to AJAX calls, or status updates with the application.

If I try and include any HTML in the body of my index.html page, it gets replaced by jQuery Mobile immediately. I don't want to have to include this div on each and every page I write.

Any ideas?

Upvotes: 2

Views: 1073

Answers (1)

Paul Grime
Paul Grime

Reputation: 15104

I don't think divs get replaced. For example, this will bring the first unseen div to the top:

http://jsfiddle.net/RQkrj/2/

<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<style>
.top {
    z-index: 999;
}
</style>
<script>
$('div#page').live('pageshow', function(event, ui) {
    $('div#doesNotGetRemoved').addClass("top");
});
</script>
</head>
<body>

<div id="doesNotGetRemoved" style="background: red; position: absolute;">This is a div</div>

<div id="page" data-role="page">

    <div data-role="header">
        <h1>My Title</h1>
    </div><!-- /header -->

    <div data-role="content">    
        <p>Hello world</p>        
    </div><!-- /content -->

</div><!-- /page -->

</body>
</html>

Upvotes: 1

Related Questions