Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the label of a JQuery Mobile checkbox

I have the following checkbox:

<input type="checkbox" id="ui-5"/><label for="ui-5">checked</label>

I'd like to change its value to unchecked if its not checked and checked if it is checked. I've tried this code:

$("#ui-5").click(function(){
   $("label[for='ui-5']").text("unchecked");
});

It changes the label but the design of my checkbox becomes weird. How can I fix this?

like image 256
Chinchan Zu Avatar asked Sep 02 '11 07:09

Chinchan Zu


1 Answers

JQuery mobile changes the original html of the page, this seems to work:

 $("#ui-5").change(function () {
    $("label[for='ui-5'] span.ui-btn-text").text("unchecked");
 });
like image 97
pauloya Avatar answered Nov 22 '22 08:11

pauloya