views:

166

answers:

1

i have a dynamic html table and in one column i want a jquery ui date picker. A few questions:

  1. Can i have datepicker by class instead of id:

    $(document).ready(function(){
    $(".datepicker").datepicker();
    });

  2. Can i create them on the fly if i i am adding in textboxes with this class using jquery?

+3  A: 
  1. You can have the datepicker based on any jQuery selector you'd like. The .datePicker() just gets applied to whatever your selector returns.

  2. Yes, you can create them on the fly, you just need to run the .datePicker() on your selector once you're read, same as you would in the document.ready(). Simply adding a textbox with the same class used in your document.ready code won't automatically set them up though, you need to make sure you run the .datePicker code again (unless you do something with .live queries).

Clarification for comment:

You'd want to avoid running the datepicker on something that's already had it run (but I don't think it will hurt if you do). So you could so something like giving the new TR in your table a unique ID (say the ID of the record?) and then run $('#newRowId input.datePicker').datePicker();.

Parrots
for #2, would i keep just repetitively call ".datepicker().datepicker(). wouldn't that reset the ones already created ?
ooo