I've got a button that I use with jQueryUI somethink like this (simplified).
<button id="mybutton">Play<button> <script> $("#mybutton").button().toggle( function(){ $(this).text('Stop'); }, function(){ $(this).text('Start'); }, ); </script>
This code breaks the way the button looks because when making it into the button widget, there's a new span added inside the button. So I'm changing the button value like this now
$(this).find('span').text('Stop');
This is hacky because I can't treat the button as a black box anymore and have to go inside.
Is there a clean way to do this?
To change the button text, first we need to access the button element inside the JavaScript by using the document. getElementById() method and add a click event handler to the button, then set it's value property to blue . Now, when we click on our button , it changes the value from Red to Blue or vice versa.
Maybe you could use the label
option of the jQuery UI button now instead?
$("#mybutton").button().toggle(function() { $(this).button('option', 'label', 'Stop'); }, function() { $(this).button('option', 'label', 'Start'); });
jsbin preview here
You can use the .button("refresh") method after you alter the text.
$("#mybutton").button().toggle( function(){ $(this).text('Stop').button("refresh"); }, function(){ $(this).text('Start').button("refresh"); }, );
http://jqueryui.com/demos/button/#method-refresh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With