oop - Javascript add new order id to each new element -
sorry english don't how correct ask question!!
i have task list , when add new task ned add smomthing ordinal number each new task
example task 1 have stored var whit id 1,task 2 var id 2 ..... think need use iteration how...? project link
var todolist = function() { var addnewtask = function() { var input = document.getelementbyid("taks-input").value, itemtexts = input, cola = document.getelementbyid('task-col-a').children.length, colb = document.getelementbyid('task-col-b').children.length, taskboks = document.createelement("div"); taskboks.classname = "min-box"; taskboks.innerhtml = '<div class="col-3 chack" id=""><i class="fa fa-star"></i></div><div class="col-8 task-text" id="taskcontent"><p>' + itemtexts + '</p></div><div class="col-1 color"></div>' if (colb > cola) { var todolist = document.getelementbyid("task-col-a"); } else { var todolist = document.getelementbyid("task-col-b"); } todolist.appendchild(taskboks); }, addbutton = function() { var btn2 = document.getelementbyid("add-task-box"); btn2.onclick = addnewtask; } addbutton() }; todolist();
just use id="task_' + (taskcount++) + '"
var todolist = function() { var taskcount = 0 var addnewtask = function() { var input = document.getelementbyid("taks-input").value, itemtexts = input, cola = document.getelementbyid('task-col-a').children.length, colb = document.getelementbyid('task-col-b').children.length, taskboks = document.createelement("div"); taskboks.classname = "min-box"; taskboks.innerhtml = '<div class="col-3 chack" id="task_'+(taskcount ++)+'"><i class="fa fa-star"></i></div><div class="col-8 task-text" id="taskcontent"><p>' + itemtexts + '</p></div><div class="col-1 color"></div>' if (colb > cola) { var todolist = document.getelementbyid("task-col-a"); } else { var todolist = document.getelementbyid("task-col-b"); } todolist.appendchild(taskboks); }, addbutton = function() { var btn2 = document.getelementbyid("add-task-box"); btn2.onclick = addnewtask; } addbutton() }; todolist();
Comments
Post a Comment