0

i am using jquery datetimepicker addon.

When the user selected the right datetime in the datetime div and pushes the "done"-button (with class ".ui-datepicker-close").

<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" data-handler="hide" data-event="click">Done</button> 

I want to use a click event on this buttons class to do some stuff.

i tried something like this:

$(".ui-datepicker-close").click(function () {
//do something
}

but this doesn't work.

Any guess?

1 Answer 1

0

Have you exactly tried this:

$(".ui-datepicker-close").click(function () {
    //do something
}//<-- missing closing ); for the click() method

or the correct version:

$(".ui-datepicker-close").click(function(){
   //dome something
}); //<-- close the click() method

EDIT

First of all -

To use this plugin you must include jQuery (1.6+) and jQuery UI with datepicker (and optionally slider).

I've checked out the addon you are using, so it's based on the standard jQuery UI Datepicker, which offers a great option onClose: , which you can use :) Documentation

Here is the correct way to trigger a function on close

$("#datepicker").datetimepicker({
    onClose: function(){
        alert("You closed me!");
    },
});

Here is a working example in a fiddle

5
  • i tried the correct version (with closed click method): $(".ui-datepicker-close").click(function(){ //do something });
    – Hank moody
    Aug 21, 2015 at 8:08
  • Ok, any errors in your console? It would be really helpful if you could add a fiddle as an example. Link to fiddle Aug 21, 2015 at 8:11
  • See jsfiddle. I try to do some statements when the button with class .ui-datepicker-close is clicked
    – Hank moody
    Aug 21, 2015 at 9:59
  • your fiddle doesn't work because you use $("#datepicker").datetimepicker({ instead of $("#datepicker").datepicker({ But thanks für the hint with onClose! that will help me a lot!
    – Hank moody
    Aug 27, 2015 at 10:58
  • using datetimepicker instead of datepicker wasn't the issue, take a look in the dev tools console next time ;) just the ressources I was loading (js and css for datetimepicker plugin) were not available anymore. I've updated my fiddle, it should work now ;) Aug 27, 2015 at 16:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.