Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: delegate and datepicker

Tags:

jquery

I need that every text input in a given class is a datepicker. Something like:

$("input[type=text].time").datepicker();

but I'm adding a lot of code via Jquery.load() so I believe I need a delegate. The problem is I don't know how to do it, because as far as I know, load event cannot be used in a delegate. It will be easy if it exists:

$(document).delegate("input[type=text].time", "load", function(){
    $(this).datepicker();
});
like image 976
Ivan Avatar asked Sep 05 '11 23:09

Ivan


1 Answers

$("body").delegate("input[type=text].time", "focusin", function(){
   $(this).datepicker();
});

I used delegate on the body because I don't know if you have your code in other containers that you can target.

Here is a fiddle that targets a specific div with delegate:

http://jsfiddle.net/MpqAy/

like image 139
jk. Avatar answered Oct 21 '22 07:10

jk.