I would like to change text on button using jquery mobile. It works if I change data-role to none, but then I lose formatting.
<fieldset class="ui-grid-a" data-inline="true">
<div class="ui-block-a"><button class="cl_button1" type="submit"
data-theme="c" data-icon="home" data-iconpos="top">Click Me</button>
</div>
</fieldset>
$('.cl_button1').val('some text');
Another posting suggested this, but it did not work.
$("cl_button1 .ui-btn-text").text("some text");
Using Firebug I found that the HTML markup created by jQuery Mobile is the following:
You can see that the
ui-btn-hidden
class has been added to the origional<button>
element and the display of the button is actually rendered through the use of the<span>
tags above the<button>
tag.So to change the text for this jQuery Mobile rendered element you would use a selector like this:
Or if you wanted to change the button's text on click you can do this:
Here is a jsfiddle for demonstration: http://jsfiddle.net/SfySk/1/
When you said this didn't work:
I got your code to work using this:
Test Here: http://jsfiddle.net/S9asF/
in jqm version 1.4.5, after initialization
It works without destroying binded events.
A better solution is to refresh the page:
All,
The above solutions do not seem to work with JQM 1.1.1. A very simple way of doing this is to call.
As per http://jquerymobile.com/test/docs/buttons/buttons-methods.html, there are only three methods you can call on a button. This should keep the internal state of your button consistent with the JQM UI adornment, and be more robust against changes to the way buttons are made 'pretty' in the future.