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>
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:So taking this HTML structure into consideration, your code should target the
.ui-btn-textelement within the<h2>element.For example:
Here is a demo: http://jsfiddle.net/XDnGs/