I want to use jQuery load to load external data on my page and then let jQuery Mobile run over it again to apply themes etc with a trigger. The data is loaded fine, but it is not reskinned properly. I just put a small example together to demonstrate this, as my entire project is too big.
I have a.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
function replaceData1() {
$("#a-page").load("b.html");
$("#a-page").trigger('create');
}
</script>
</head>
<body>
<div data-role="page" id="a-page">
<div data-role="header" data-theme="a">Header A</div><!-- /header -->
<div data-role="content" id="a-content">
Content A
<button onClick="replaceData1()">goto B</button>
</div><!-- /content -->
<div data-role="footer">Footer A</div><!-- /footer -->
</div><!-- /page -->
</body>
</html>
And I have b.html:
<div data-role="header" data-theme="d">Header B</div><!-- /header -->
<div data-role="content" id="b-content">Content B</div><!-- /content -->
<div data-role="footer">Footer B</div><!-- /footer -->
b.html is not a complete html file, just the content. I am not sure if this causes this issue or not.
Nevertheless, when I load a.html and click on the button, the contents from b.html is correctly loaded but not themed properly. Even if I execute trigger(‘create’) later, it does not work. What did I do wrong? Can somebody please rewrite this, so that it works the way I intended it?
try this