Change data icon when clicked on jquery mobile

This is my code:

function togglePOIAndDisplay(toggle){
    var display = $(toggle).attr('data-icon');
    console.log(display);
    if(display == 'minus'){
        $(toggle).attr('data-icon', 'check');
            console.log(display);
    } else {
        $(toggle).attr('data-icon', 'minus');
        removeMarkers(toggle);
    }
}   

It will write minusto the console and go to the first if () block and correctly execute displayAllPOIOfType (), but it will not reflect the change in value, although it will be set correctly. Any ideas why this is so, because it explicitly reads / sets the attribute correctly.

Is there an update functionI need to call? thank

+5
source share
4 answers

, - , data-icon. , jQuery Mobile , data-*, , .

, - :

$(buttonSelector).attr('data-icon', newIcon);
                 .find('.ui-icon')
                     .addClass('ui-icon-' + newIcon)
                     .removeClass('ui-icon-' + oldIcon);
+16

, :

<a id="buttonID" href="#" data-role="button" data-icon="delete">Button</a>

buttonMarkup:

$('#buttonID').buttonMarkup({ icon: "check" });

:

$('#buttonID').buttonMarkup({ icon: "my-icon" });

: http://jsfiddle.net/u8fnJ/1/

jQueryMobile?

+7

http://jsfiddle.net/phillpafford/8pwFK/29/

.

$(this).attr('data-icon','star');
$(this).find('.ui-icon').removeClass('ui-icon-custom').addClass('ui-icon-star');

.

0

.

$("#times").off('click','li').on("click","li",function() {

 /* add a checkbox when you click the listview li  */
 $(this).find('div.ui-li').append('<span class="ui-icon ui-icon-check ui-icon-shadow">&nbsp;</span>');

});
-1

All Articles