12

I have the following code for the jQuery UI datepicker:

$(function() {
        $(".date").datepicker({
            showOn: 'button',
            buttonText: "Choose Date",
            dateFormat: 'yy-mm-dd'
        });
    });

It creates a button on the side of the text box so people can click the box and select a date. Is it possible to apply a class to the button that is created so I can apply a CSS style to it?

2 Answers 2

25

You can't add an additional class through an option, but it does have a class: ui-datepicker-trigger, so if you just style directly or as a descendant of an identifiable container it'll work, for example:

.ui-datepicker-trigger { color: red; }
//or...
.myContainer .ui-datepicker-trigger { color: red; }

Or, add a different class to the button manually after creating the datepicker (which creates the button):

$(function() {
    $(".date").datepicker({
        showOn: 'button',
        buttonText: "Choose Date",
        dateFormat: 'yy-mm-dd'
    }).next(".ui-datepicker-trigger").addClass("someClass");
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much! It work as: .ui-datepicker-trigger {color:red;} No need to put the .dateContainer
@Doug - I wasn't sure if you wanted it more specific or not, just giving you options :) glad either approach was what you were looking for :)
It's better more specific sometimes because you may have more that one datepicker on the same page.
1

Make it become a jQuery UI button since you already have the framework loaded ;)

http://www.robertmullaney.com/2011/08/26/make-jquery-datepicker-use-ui-button/

Disclaimer: My Blog

Comments

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.