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 8725207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:59:21+00:00 2026-06-13T07:59:21+00:00

I have a div that is dynamically populated with other divs… <div id=wrapper> </div>

  • 0

I have a div that is dynamically populated with other divs…

<div id="wrapper">

</div>

//javascript 
 for(//a bunch of times){
  var d = document.cloneNode('divModel');
  d.foo = {//bunch of stuff };
  document.getChildById('wrapper').appendChild(d) is applied later to fill in child divs
}

Now I would like to loop through the children of wrapper and do something with that foo.

When I do it via normal javascript

document.getElementById('wrapper').childNodes[x].foo

That works as I would expect

However

$('#wrapper').each(function (i, element){
      console.log(element.foo); //foo here is undefined
})

results in a bunch of undefined

So… I’m guessing that jQuery is actually dealing with some internal wrapper to my divs rather than the divs directly. I’m curious how (or if it’s possible) I can access the actual divs in this loop so as to access my custom foo.

EDIT
Based on all your answers so far (and thanks very much for the time) I feel like I need to clarify, cause everyone seems to be missing my actual question…
I’ve modified the code above to be more explicit.

I don’t have a syntax error (in my actual code). jQuery cycles through the wrapper children correctly, it’s just not returning the ACTUAL children (divs) it’s returning its own version of them, and this custom version doesn’t contain my appended foo.

So, what I need is to be able to get back to the actual dom object, not the jQuery wrapper around it. Is this possible?

  • 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-06-13T07:59:22+00:00Added an answer on June 13, 2026 at 7:59 am

    You’re right exactly, except the selector is off. You need $("#wrapper").

    $("#wrapper").each(function(i,e) { console.log(e.id) });
    

    Edit

    Confirming that it’s possible to get an object back from a DOM element …

    var c = document.getElementById('container');
    var el = document.createElement('div');
    el.id = 'new';
    el.innerText='the test element';
    el.test = { hello: "world" };
    c.appendChild(el);
    console.log('javascript: ' + document.getElementById('new').test.hello);
    $("#container div").each(function(i,e) {
        if (e.test) console.log('jquery: ' + e.test.hello);
    });
    

    http://jsfiddle.net/eeYHr/3/
    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JavaScript function that is supposed to generate a <div> dynamically and
I currently have a a scrollable div that is populated dynamically. I have a
I have some javascript/jquery code that dynamically populates an unordered list with a bunch
I am loading some text dynamically into a div, but have the problem that
I have a div that will serve as container to other element, I have
I need to load a HTML wrapper dynamically depending on data that gets populated
I have a div tag which I populate dynamically. The problem is that in
Ok so I have a div that contains a few forms that have dynamically
So I have a div that gets content dynamically, and when the content size
I have a webpage that dynamically prepends new divs about once per minute. Here

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.