li element not rendering 10 times
I have declared an li element as global and tried to push the same in
array. Later I appended the same in ul but only once li item got displayed
instead of displaying it 10 times.
var items = [], ele = $("<li>brad</li>");
for(var i=0; i<10; i++) {
items.push(ele);
}
$("#myId").append(items);
But if the li element is declared within loop as below:
for(var i=0; i<10; i++) {
ele = $("<li>brad</li>")
items.push(ele);
}
It displayed li 10 times. I couldn't figure out the reason for that. Why?
No comments:
Post a Comment