I need loop in Javascript - when You click on button it add ol tu ul and gave id with number, like this:
<ol id="single-task1"></ol>
<ol id="single-task2></ol>
And so on...
When I tried whit loop like this:
taskNumber = 0;
for (var i; i<999; i++){
taskNumber++;
}
var ol = document.createElement('ol'); //creating element ol
taskValue = textField.value; //getting value from user
taskList.appendChild(ol); //add ol to ul
ol.id = 'single-task-'+taskNumber;
ol.innerHTML = taskValue; //add value from user to new ol
All ol elements still have "single-task-0"... Probably loop is in wrong place or loop is wrong.
ol-element. Try using a debugger within your browser to see what your code is doing.<ol>elements inside a<ul>? Did you mean<li>? Do you really need one thousand IDs? Why not simplytaskList.children[taskNumber]?