Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making datepicker live - JQuery

I know when you create an element dynamically, you have to use something like:

$("#id").live("click", function() {
    //something
});

Right now I have this:

$('#tdInput1').datepicker({
    inline: true
});

My question is: how do I make this live so it can interact with dynamically created elements.

like image 608
craigtb Avatar asked Jul 06 '11 18:07

craigtb


1 Answers

The accepted solution won't work with keyboard focus events.. so I had to change to this:

$('.parent').on('focusin', '.datepicker', function(e) {
    $(this).datepicker(options);
});

Had to change .live to .on since jquery 1.9.1 doesn't include the .live method. The above works for the mouse events as well as keyboard focus events.

like image 145
Vishal Avatar answered Sep 30 '22 22:09

Vishal