Add datepicker to dynamically CLONED content ISSUE

Add datepicker to dynamically CLONED content ISSUE


When adding new content to a page client side using jQuery by cloning
an existing item, like a textbox, and adding the datepicker to it
sounds real easy, and it is:
var $existing = $('somecontentwithdatepicker').clone(); (did not use
clone(true) since don't want all the events)
$existing.datepicker().insertAfter('someother');
However this will not work! You ALSO need to remove the class
"hasDatepicker" from the cloned item since the datepicker adds it when
it has set it. So to make sure, and don't try and use "removeClass
('hasDatepicker')" as it also does not work:
var datePick = /hasDatepicker/g;
var $lastLine = $('mynewline:last').html();
$lastLine = $lastLine.replace(datePick,'');
$('mynewline:last').empty().html($lastLine).datepicker();
Done, works like a charm.