Hello everyone,
I formerly had my datepicker appearing when I was applying it to a static element, but for some reason I can't get it to work dynamically. Under certain configurations, it works if I pop up an alert box first. What is wrong?
div.load(url, function() {
div.children().each( function(){this.datepicker({dateFormat:"yy-m-d"}});
div.appendTo("div#foos_container");
});
Here is some more context:
Javascript:
add_foo = function(url) {
// Clickable
var numfoos = $("div#foos_container > div.foo").length + 1;
var foo_id = numfoos + "-foo";
var div = $("<div></div>").attr("id",foo_id).addClass("foo");
div.load(url, function() {
div.children().each(function(){
// what do expect this to be below?
// this will be a child element here, so need
// to wrap to get a jQuery object
$(this).datepicker({dateFormat:"yy-m-d"});
});
div.appendTo("div#foos_container");
});
HTML:
<a id="add_foo" onclick="add_foo('{% url add-foo %}')" class="ajax_link">Add Foo</a>
<div id="foos_container">
</div>
Thank you!
EDIT: Added context. I should note that the HTML is a django template.