Storing DOM reference elements in Javascript array
Posted
by webzide
on Stack Overflow
See other posts from Stack Overflow
or by webzide
Published on 2010-05-23T23:49:59Z
Indexed on
2010/05/24
0:01 UTC
Read the original article
Hit count: 259
JavaScript
|dom
Dear experts, I was trying to dynamically generate DOM elements using JS.
I read from Douglas Crockford's book that DOM is very very poorly structured.
Anyways, I would like to create a number of DIVISION elements and store the reference into an array so it could be accessed later.
Here's the code
for(i=0;i<3;i++){
var div=document.body.appendChild(document.createElement("div"));
var arr=new Array();
arr.push(div);
}
Somehow this would not work..... There is only 1 div element created. When I use the arr.length to test the code there is only 1 element in the array.
Is there another way to accomplish this.
THanks in advance
© Stack Overflow or respective owner