Test if element already has jQuery datepicker

Posted by macca1 on Stack Overflow See other posts from Stack Overflow or by macca1
Published on 2010-04-05T16:00:37Z Indexed on 2010/04/05 16:03 UTC
Read the original article Hit count: 288

I have a form with many input elements. Some are date fields with a jQuery UI datepicker alraedy attached:

$("#someElement").mask("9?9/99/9999").datepicker({showOn: 'button', buttonText:'Click here to show calendar', duration: 'fast', buttonImageOnly: true, buttonImage: /images/calicon.gif' });

Then I have a key command bound to this function:

function openCalendar() {
    var selection = document.activeElement;

    // { Need to test here if datepicker has already been initialized 
        $(selection).datepicker("show");
    // }
}

This works great for elements which already have the datepicker on them. However any other fields will throw a javascript error. I'm wondering the best way to test to see if datepicker has already been initialized on that field.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui