Is there a way to know if a textfield is an instance of jQuery UI Datepicker?
In example, lets say I have this code:
$('#item_id').datepicker();
Is there a way to do something like this:
if($('#item_id') IS NOT A DATEPICKER YET)
{
$('#item_id').datepicker();
}
The above conditional check, of course, is in human language and not JavaScript regular code 😉
PS: I know my question is very general, but my English are not so good 🙁
Once a textfield has been applied with a JQuery UI Datepicker, it will contain a ‘hasDatepicker’ class.
Perhaps you can form a query like
$('#field').hasClass('hasDatepicker')to check if the a specific textfield with id ‘field’ has a datepicker feature applied on it. Make sure you do the check after the datepicker has been applied, not before.Alternatively, you can just do a check of the same classes used to apply the datepicker.
If you use
$(".applyDatepicker").datepicker();to apply the datepicker on all textfield with ‘applyDatepicker’ class. Then you can just backtrack with$('#field').hasClass('applyDatepicker').