Reputation: 541
When I dynamically change the h2 content of a collapsible list in jquery mobile 1.2 the h2 tag looses it's formatting.
Calling listview('refresh') does not seem to fix it.
Any ideas?
<div id="mylist" data-role="collapsible" data-theme="a" data-content-theme="a" data-mini="true" >
<h2>Choose...</h2>
<ul data-role="listview">
<li data-mini="true"><a href="#">Item 1</a></li>
<li data-mini="true"><a href="#">Item 2</a></li>
<li data-mini="true"><a href="#">Item 3</a></li>
</ul>
</div>
<script>
$("#mylist li").live( 'click',function(event){
$("#mylist h2").text($(this).text());
$("#mylist").listview('refresh');
});
</script>
Upvotes: 0
Views: 250
Reputation: 76003
You are overwriting the HTML structure that jQuery Mobile creates for your collapsible widget. The HTML structure of the <h2>
element you're attempting to update looks like this after initialization from jQuery Mobile:
<h2 class="ui-collapsible-heading ui-collapsible-heading-collapsed">
<a href="#" class="ui-collapsible-heading-toggle ui-btn ui-mini ui-btn-icon-left ui-corner-top ui-corner-bottom ui-btn-up-a" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="span" data-icon="plus" data-iconpos="left" data-theme="a" data-mini="true">
<span class="ui-btn-inner ui-corner-top ui-corner-bottom">
<span class="ui-btn-text">
Choose...
<span class="ui-collapsible-heading-status"> click to expand contents</span>
</span>
<span class="ui-icon ui-icon-plus ui-icon-shadow"> </span>
</span>
</a>
</h2>
So taking this HTML structure into consideration, your code should target the .ui-btn-text
element within the <h2>
element.
For example:
$(document).on('click', "#mylist li", function(event){
$("#mylist h2 .ui-btn-text").text($(this).text());
});
Here is a demo: http://jsfiddle.net/XDnGs/
Upvotes: 1