leora leora - 1 year ago 81
jQuery Question

can i have dynamic date pickers using jquery by class selector

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:




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

Answer Source
  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();.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download