2

After dynamically updating a header tags text for an existing collapsible element, the styling disappears, even though im calling .collapsible({refresh: true}) after updating.

jsFiddle: http://jsfiddle.net/RAxn5/ (click the 'Break it' link to see what i mean).

HTML:

<div id="set" data-role="collapsible-set">
    <div data-role="collapsible" id="set1" data-collapsed="false">
        <h2 class="section_title">Section 1</h2>
        <ul data-role="listview">
            <li><a href="#"><h3>item 1</h3></a></li>
            <li><a href="#"><h3>item 2</h3></a></li>
            <li><a href="#"><h3>item 3</h3></a></li>
        </ul>
    </div>
</div>

<a href="#" id="break">Break it</a>

JS:

$('#break').click(function() {
    $('#set1 h2.section_title').text('Now my style is gone!');
    $('#set1').collapsible({refresh: true});
});

Thanks in advance.

Dave
  • 23
  • 3
  • 1
    This should help you: http://stackoverflow.com/questions/7857218/jquery-mobile-dynamically-change-the-text-of-the-header-of-a-collapsible-div The issue is caused by the additional elements that jQuery mobile adds. – David Ziemann May 16 '13 at 14:24
  • 1
    I appreciate your quick response mate, you lead me on the right track but it was ultimately Omars answer that i ended up using. I really wish i could select both answers. – Dave May 16 '13 at 14:50

2 Answers2

2

Add it to span.ui-btn-text not to h2.

Demo

$('#set1 span.ui-btn-text').text('Now my style is gone!');
Omar
  • 32,302
  • 9
  • 69
  • 112
1

An easy solution (although a bit hacky) is to find the span that the button sets up and change that rather than the parent id.

$('#set1 h2.section_title').find('.ui-btn-text').text('Now my style is gone!');

Here is the JSFiddle for it.

David Ziemann
  • 960
  • 1
  • 8
  • 22
  • Yeah that's the main thing to me - it feels very hackish and i would have thought there'd be some refresh event/jquery mobile function to call - i've not been able to find anything. – Dave May 16 '13 at 14:55
  • It doesn't seem like they have any good options for this at the moment. It would make sense that they should include the section title into the refresh. – David Ziemann May 16 '13 at 15:05