I am using "jquery-1.9.1.js" and my javascript code is as below:
$('.fromSearch').on('focus', function(){
var $this = $(this);
if(!$this.data('datepicker')) {
$this.removeClass("hasDatepicker");
$this.datepicker();
$this.datepicker("show");
}
});
my html code is this:
<div id="duration" class="duration">
<td><input type="text" id="fromSearch" class="fromSearch"></td>
</div>
PROBLEM: I am generating "fromSearch" (date picker) dynamically, lets say 5 date pickers, but I get date picker only for the first time!
I have been working on solutions provided on similar questions, but none of them is working for me. Can any body help me figuring out where I am going wrong? Thanks for your time. :)
$(document).on('focus', '.fromSearch', function(){...});That's said, beware, IDs must be unique on document context. And BTW, your HTML markup is invalid.fromSearchelement is added after the DOM has been loaded.