0

I have a button in a form (which is styled with jQuery UI), and am dynamically changing the text with JavaScript. For some reason, changing the text makes the button size shrink to an unusual size. What can I do to remedy this?

Here is a picture of the problem:


Different button sizes


2
  • 1
    You need to post a working version on jsFiddle. There are a LOT of reasons why this could have happened. Commented Aug 29, 2012 at 15:02
  • Often, re-initializing the button creator will fix these things. Commented Aug 29, 2012 at 15:03

1 Answer 1

6

You probably change the text of the button the wrong way. For instance, if you simply do $('#button').text('Test') or $('#button').html('Test') you will overwrite the span element jQuery emits for styling purposes.

Try this:

$('#button').find('span').text('Test');

EDIT:

I just found a cleaner way to do this:

$('#button').button('option', 'label', 'Test');
Sign up to request clarification or add additional context in comments.

1 Comment

finally!..It works perfectly and this theory solves lots of same kind of problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.