How do I replace jQueryUI button text?

Posted by Andrei Railean on Stack Overflow See other posts from Stack Overflow or by Andrei Railean
Published on 2010-04-19T07:55:44Z Indexed on 2010/04/19 8:03 UTC
Read the original article Hit count: 409

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jqueryui