I am trying to find a way to change the button in the header without losing formatting. I want to change the Delete button using the Delete icon to the Finish button using the validation icon.
Here's a shortened version of the code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
<script type="text/javascript">
function swapButton() {
$('#button').attr('data-icon', 'check').text('Done').trigger('create');
$('#header').trigger('create');
}
</script>
</head>
<body>
<div data-role="page">
<div data-role="header" data-position="fixed" id="header">
<a data-icon="delete" id="button" onclick="swapButton()">Delete</a>
<h1>Test Page</h1>
</div>
<div data-role="content">
<p>Click on Delete to get Done button</p>
</div>
</div>
</body>
</html>
This changes the button text correctly, but all formatting disappears.
I tried using trigger('create')both on the button and on the header, which does not work, I also tried the method .page()that I read in the answer elsewhere, and I also tried .button().
I can't think of anything else to try.
source
share