Ben Pearce
Ben Pearce

Reputation: 7094

Strange behavior in jQuery Mobile nested list views

I'm experimenting with nesting listviews in jQuery Mobile. In the code below I have three list elements all of which contain a '.sub-list' element with 'display:none'. The prescence of the '.sub-list' elemnt cause two odd behaviors.

  1. The precence of the 'sub-list' elements causes '#main-list' to be css formatted, i.e. the list elements have a gradient on the color and when you mouse over it changes color as well.

  2. The precence of the '.sub-list' elements cause the '.main-list-element' list elements to link to a new page with the '.main-list-element' text at the top of the page. Can anyone tell me why this is happening and how to prevent it?

Please note I have experimented with jQuery Mobile collapsable content and have ruled out using it.

<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
</head>
<body>
 <div data-role="page" id="date-page" class="type-interior" style="width:100%">
<ul id='mainlist' data-role="listview" class='list-element'>
<li class='main-list-element'>test 1<ul class='sub-list' data-role="listview" style='display:none'></ul></li>
<li class='main-list-element'>test 2<ul class='sub-list' data-role="listview" style='display:none'></ul></li>
<li class='main-list-element'>test 3<ul class='sub-list' data-role="listview" style='display:none'></ul></li>
</ul>
</div>
  <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
      <script src="http://jquerymobile.com/demos/1.2.0-alpha.1/docs/_assets/js/jqm-docs.js"></script>
      <script src="http://jquerymobile.com/demos/1.2.0-alpha.1/js/jquery.mobile-1.2.0-alpha.1.js"></script>
<script>
   $('.list-element').click(function(){
   alert("hi");
   });
</script>
</body>
</html>

Upvotes: 1

Views: 537

Answers (1)

Omar
Omar

Reputation: 31732

Update:

Here is an official demo of creating a Nested Listview in jQuery Mobile 1.4.


This is called Nested Listview which is deprecated as of latest stable version (1.3) and will be removed in version (1.4).

Upvotes: 3

Related Questions