Search code examples
jquerylistviewjquery-mobileicons

Dynamically change icon in jQuery Mobile listview


When I dynamically change the icon, it does not reflect the change on the page, even though in the markup it was changed.

Example:

      <ul data-role="listview" data-autodividers="true" data-filter="true" data-inset="true">
        <li data-icon="check"><a href="#">Adam Kinkaid</a></li>
        <li data-icon="check"><a href="#">Alex Wickerham</a></li>
        <li data-icon="check"><a href="#">Avery Johnson</a></li>
        <li data-icon="check"><a href="#">Bob Cabot</a></li>
        <li data-icon="check"><a href="#">Caleb Booth</a></li>
        <li data-icon="check"><a href="#">Christopher Adams</a></li>
        <li data-icon="check"><a href="#">Culver James</a></li>
    </ul>

$("li").tap(function() {
    //Alert the old icon
    alert($(this).jqmData("icon"));

    //Toggle
    $(this).jqmData("icon") == "false" ? $(this).jqmData("icon", "check") :             $(this).jqmData("icon", "false");

    //Alert the new icon
    alert($(this).jqmData("icon"));
});

http://jsfiddle.net/Mc97V/


Solution

  • I made you a working example: http://jsfiddle.net/Gajotres/qgE6L/

    $('#index').live('pagebeforeshow',function(e,data){    
        $("li").tap(function() {
            $(this).buttonMarkup({ icon: "edit" });
        });  
    });