Skip to content

Instantly share code, notes, and snippets.

@lyonsun
Created September 24, 2014 01:56
Show Gist options
  • Save lyonsun/6500c43c16fcd1495cc1 to your computer and use it in GitHub Desktop.
Save lyonsun/6500c43c16fcd1495cc1 to your computer and use it in GitHub Desktop.
change button text in jQuery mobile
/**
* Credits: http://stackoverflow.com/a/9438023/861169
*/
// Since jQuery mobile generates HTML around your input type="button" element, and the text that you're seeing isn't actually value of the button, but a text inside of a generated span. You can either traverse the DOM looking for actual span, OR tell jQuery to re-generate button HTML by calling .button("refresh"), like so:
$("#MyButton").val("changed value");
$("#MyButton").button("refresh");
// The latter is recommended, since it will stay compatible with future versions of jQuery mobile, while traversing the DOM might break if jQuery team chooses to change structure of the HTML generated for the button.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment