Steve Awsd
Steve Awsd

Reputation: 55

Button change color on click jQuery Mobile

I've this code to change a color of a button on click:

$('.fav').live('click', function(e) { 

  $(this).buttonMarkup({ theme: "b" });

});

How can I return to normal color (theme c) by clicking the button again?

Is there any way to see the state of a button?

Upvotes: 2

Views: 3575

Answers (1)

Sindre
Sindre

Reputation: 3930

As it has to be live then you could just make your own toggle:

$('.fav').live('click', function() {
    var dotoggle = $(this).attr("dotoggle");
    if ( dotoggle == "1"  ) {
        $(this).buttonMarkup({ theme: "c" });
        $(this).attr("dotoggle","0");
     }
     else {
        $(this).buttonMarkup({ theme: "b" });
        $(this).attr("dotoggle","1");
    }
});

JSFiddle of a custom toggle example: http://jsfiddle.net/PLx8v/3/

Upvotes: 1

Related Questions