Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have to call $(":button").button(); to enable JQuery UI Theme?

I am still new to JQuery and JQuery UI Theme. I have managed to develop my own theme, and to apply it on a simple test page with buttons. I read the documentation, and I could not find where it says that I should explicitly call $(":button").button(); to apply it.

If I don't do this, the theme is not applied. So why do I have to do this explicitly? Or if this is expected from me, does anyone have a generic script to apply the theme automatically on all items? Thanks.

EDIT

Reading answers and comments, some people imply that application of UI Theme is automatic, but others say it should be applied manually. A test on the delivered test HTML page seem to indicate that theme must be applied manually.

like image 331
Jérôme Verstrynge Avatar asked Dec 12 '22 08:12

Jérôme Verstrynge


2 Answers

If you look at the demos, the button styles can be applied to other elements as well, such as checkboxes, radio buttons and anchors. jQuery UI thinks it is better to let you specify which elements should have that particular style applied than to try to guess, especially since specifying the elements is typically a one-liner: $(foo).button();

like image 126
Dennis Avatar answered Dec 28 '22 23:12

Dennis


The reason you have to call the button function, is so that jQuery UI can add all of its specialized classes and attributes to the button.

If you start off with a button like this:

<button type="button">A button element</button>

It will be replaced with this:

<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">A button element</span></button>
like image 33
Sunjay Varma Avatar answered Dec 29 '22 00:12

Sunjay Varma