Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  26] [ 4]  / answers: 1 / hits: 15638  / 15 Years ago, sun, october 18, 2009, 12:00:00

Thanks for looking, all sincerely helpful answers are up-voted.
I have some date input fields that are there when the page loads and a bunch that get generated dynamically. Instead of calling .datepicker() on that class each time a new instance is generated, I'm using .live, but it doesn't seem to be working. Any idea why?



$(input[name=myfav]).live(click, function(){
$(this).datepicker({
/* some options here */
});
});


I should mention, it works perfectly fine with autocomplete for instance.



$(input[name=mytwo]).live(click, function(){
$(this).autocomplete(somefile.php);
});

More From » jquery

 Answers
8

Here is an article about the datepicker using the .live-event in jQuery:



http://www.vancelucas.com/blog/jquery-ui-datepicker-with-ajax-and-livequery/



The problem is that the Datepicker works by binding to the focus() event by default, but as of jQuery 1.3.2, the ‘focus’ event cannot be monitored by the ‘live’ event function.



Here is the work-around from the site::



<script type=text/javascript>
$(function(){
$('input.calendarSelectDate').live('click', function() {
$(this).datepicker({showOn:'focus'}).focus();
});
});
</script>





EDIT: This workaround is no longer needed as jQuery 1.4.1+ now supports focus and blur events for live(). (Thanks @Chris S)


[#98492] Tuesday, October 13, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mustafaericho

Total Points: 322
Total Questions: 103
Total Answers: 110

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
mustafaericho questions
Mon, May 31, 21, 00:00, 3 Years ago
Sun, May 23, 21, 00:00, 3 Years ago
Sat, Feb 13, 21, 00:00, 3 Years ago
Sat, Jan 2, 21, 00:00, 3 Years ago
Thu, Nov 12, 20, 00:00, 4 Years ago
;