Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  16] [ 4]  / answers: 1 / hits: 156997  / 12 Years ago, thu, may 3, 2012, 12:00:00

I have dynamically created textboxes, and I want each of them to be able to display a calendar on click. The code I am using is:



$(.datepicker_recurring_start ).datepicker();


Which will only work on the first textbox, even though all my textboxes have a class called datepicker_recurring_start.



Your help is much appreciated!


More From » jquery

 Answers
7

here is the trick:



$('body').on('focus',.datepicker_recurring_start, function(){
$(this).datepicker();
});​


DEMO



The $('...selector..').on('..event..', '...another-selector...', ...callback...); syntax means:

Add a listener to ...selector.. (the body in our example) for the event ..event.. ('focus' in our example). For all the descendants of the matching nodes that matches the selector ...another-selector... (.datepicker_recurring_start in our example) , apply the event handler ...callback... (the inline function in our example)



See http://api.jquery.com/on/ and especially the section about delegated events


[#85818] Wednesday, May 2, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyterryp

Total Points: 290
Total Questions: 92
Total Answers: 95

Location: Montenegro
Member since Sun, May 7, 2023
1 Year ago
;