Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 506871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:44:44+00:00 2026-05-13T06:44:44+00:00

I formerly had my datepicker appearing when I was applying it to a static

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:44:45+00:00Added an answer on May 13, 2026 at 6:44 am

    try

    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("#foos_container");
    });
    

    In light of your edit, try the following.

    add_foo = function(url) {
        // Clickable
        var numfoos = $("#foos_container > div.foo").length + 1;
        var foo_id = numfoos + "-foo";
        var div = $("<div></div>").attr("id",foo_id).addClass("foo");
    
        div.appendTo("#foos_container").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"}); 
        });        
    
    };
    

    What do you expect the this to be in div.children().each( ...) ?

    EDIT:

    Here’s a Working Demo which simulates what I believe you are trying to achieve. Add /edit to the URL to see the code and play with it (example below).

    <a id="add">Click me to add a div via AJAX Load</a>
    <div id="foos_container"></div>
    
    $(function() {
    
        $('#add').click(function() {
    
            var numfoos = $("#foos_container > div.foo").length + 1;
            var foo_id = numfoos + "-foo";
            var div = $("<div></div>").attr("id",foo_id).addClass("foo");
    
            div.appendTo("#foos_container").load("http://jsbin.com/ejalo", function() {
                div.children().each(function(){ 
                    $(this).datepicker({dateFormat:"yy-m-d"}); 
                });                
            });                 
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to redirect some urls. Formerly I had http://mysite.com/foobar/?section_id=1234 These are no pointing
I formerly asked for a Best-Practice regarding this, But this is one the strategies
I realize that a SO user has formerly asked this question but it was
Formerly I was using MyISAM storage engine for MySql and I had defined the
Our company recently began creating CVS branches to mark each release. Formerly we had
I have a case i hadn't formerly, and really can't figure it out, what
I’ve come to Git from SVN. Formerly in order to update some production site
I'm using Diazo (formerly XDV) to theme some internal websites, using Apache and mod_transform_html
Can someone please compare and contrast Passenger Standalone (formerly Passenger Lite) and Unicorn. I
How do I get timezone information on macOS (formerly known as Mac OS X

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.