I was trying to add a div for each element in the distinctCtyNames
array. However if I press the button once, it only create a few divs and I have to press the button multiple time in order to pop all the elements and make them divs.
When I use for(i=0;i<length;i++){ctyName = distinctCtyNames[i] /*and create div*/}
, there is no such problem
my code is as following:
<input type="submit" name="BtnLogin" value="addDiv" onclick="addDiv()" id="addDiv" style="height:26px;width:100px;Z-INDEX: 105; LEFT: 440px; TOP: 72px"/>
and
console.log(distinctCtyNames);
for (ctyName in distinctCtyNames){
var element = document.createElement('div');
ctyName = distinctCtyNames.pop();
element.id = ctyName;
element.style['cssText'] = "width: 1000px; height: 400px; margin: 0px auto;"
oContent.appendChild(element);
}