Change data-icon on click with jquery mobile

前端 未结 4 1149
独厮守ぢ
独厮守ぢ 2021-01-18 12:58

This is my code:

function togglePOIAndDisplay(toggle){
    var display = $(toggle).attr(\'data-icon\');
    console.log(display);
    if(display == \'minus\'         


        
4条回答
  •  醉话见心
    2021-01-18 13:45

    This depends on whether it's a button, or a select, or some other thing that accepts the data-icon attribute. Unfortunately, jQuery Mobile doesn't have great support for dynamically changing things controlled by data-* attributes, so you'll have to adjust the attribute as well as modify the classes on the child elements.

    For buttons, something like this ought to work:

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

提交回复
热议问题