7

I have multiple datepicker controls on single page binded to input controls. When I click on any of the input control datepicker control linked to that input gets visible.

Now I want to get input for which the current instance of datepicker is being shown on another JS events. Is it possible?

1 Answers1

10

You can try using the $.datepicker._getInst(target) method to get any specific datepicker on your page. You just have to pass in a target element, which you can do so by just passing the id using document.getElementById (don't use JQuery or it will return undefined).

So like so:

var id = document.getElementById('someId'); 
//replace someId with the id of the datepicker currently visible.  
var inst = window.$.datepicker._getInst(id);

This is especially helpful if you are trying to get the current instance of a datepicker that's an inline element (not attached to an input).

vijayxtreme
  • 116
  • 2
  • 7
  • I have attached datepicker to some HTML textboxes using CSS class name & `onSelect` event handler I need to know the selector class name on which current `onSelect` happened.. the elements have 2 other classes applied other then the one I am using to attach datepicker – techie_28 Aug 31 '16 at 06:29
  • 4
    Thanks for this! You can actually use jquery but use index [0] to get the actual DOM element. `var elem = jQuery('#someId'); var inst = jQuery.datepicker._getInst(elem[0]);` – plong0 Sep 22 '16 at 21:36