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?
You’re right exactly, except the selector is off. You need
$("#wrapper").Edit
Confirming that it’s possible to get an object back from a DOM element …
http://jsfiddle.net/eeYHr/3/