jQuery Mobile Dynamic Content Insertion

2k views Asked by At

Ok, would someone help me figure out why the "test" li in the following code isn't visible? I inspected the live dom and the elements do seem to be getting processed:

<!DOCTYPE HTML> 
<html> 
<head> 

  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
  <script>
  $(document).ready(function(){
      $('<div data-role="content" class="content"><ul data-role="listview" data-inset="true"><li><a href="#im?at=animals">test</a></li></ul></div>').appendTo("#home").page();
      $.mobile.changePage("#home", {transition: "none"});
  });
  </script>
</head> 

<body> 
<div id="home" data-role="page"> 
</div> 
</body> 
</html>

Thanks in advance.

2

There are 2 answers

2
Minras On

The element below has display property set to none and it hides its siblings:

<div data-role="content" class="content ui-page ui-body-c ui-content" tabindex="0" role="main">

The CSS rule:

.ui-mobile [data-role="page"], .ui-mobile [data-role="dialog"], .ui-page {
top: 0;
left: 0;
width: 100%;
min-height: 100%;
position: absolute;
display: none;
border: 0;
}
0
nxt On

The call to changePage doesn't work because you only have a single page which is visible/active by default. You can force the active page to update by triggering the create event.

$('<div data-role="content" class="content"><ul data-role="listview" data-inset="true"><li><a href="#im?at=animals">test</a></li></ul></div>').appendTo("#home");
$.mobile.changePage("#home", {transition: "none"});  
$.mobile.activePage.trigger('create');