Why is my dynamic data loading and refresh not working?

Why is my dynamic data loading and refresh not working?

Hello,

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:
  1. <!DOCTYPE html> 
  2. <html>
  3.       <head>
  4.       <meta charset="utf-8">
  5.       <meta name="viewport" content="width=device-width, initial-scale=1"> 
  6.       <title>Test</title>
  7.       <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
  8.       <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
  9.       <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
  10.     
  11.       <script>    
  12. function replaceData1() {
  13. $("#a-page").load("b.html");
  14. $("#a-page").trigger('create');
  15. }    
  16.     </script>
  17. </head> 
  18. <body> 

  19. <div data-role="page" id="a-page">
  20.             <div data-role="header" data-theme="a">Header A</div><!-- /header -->
  21.         
  22.             <div data-role="content" id="a-content">
  23.             Content A
  24.             <button onClick="replaceData1()">goto B</button>
  25.             </div><!-- /content -->

  26.             <div data-role="footer">Footer A</div><!-- /footer -->

  27.             </div><!-- /page -->
  28. </body>
  29. </html>

And I have b.html:

  1. <div data-role="header" data-theme="d">Header B</div><!-- /header -->
  2.         
  3.         <div data-role="content" id="b-content">Content B</div><!-- /content -->

  4.         <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?