Dynamic div id

torwald.lung67

New Member
Messages
14
Reaction score
0
Points
0
Hi.
I have found my old script, review code and like to bring them back to live but...
part of the code dynamicly creates meny DIV elements:
for (i=0;i<100;i++){
document.write('<div id="star">*</div>');
}
now access to any style property in old times looked like this (for example ie):
i=1 // or any number from 0 to 99
document.all.star.style......
Today it works in "ie8" and "chrome" but i like to rewrite script useing getElementById metod. It is hard to use old fassion metod becouse of compatybility with all major browsers.
So... any clues how to dynamicly give unique id to dynamicly created divs?


...............

Ok problem solved (for: firefox 3.6.15, chrome 5.2.0, IE 8.0). if u need solution for similiar problem:
for (i=0;i<10;i++){
document.write('<div id="star'+i+'" style="width:10px;height:10px;background-color:red;">*</div>');
}

access to element:
for (i=0;i<10;i++){
document.getElementById("star"+i).innerHTML="any text";
}
 
Last edited:
Top