0
Js: How to put created elements in order ...
Meaning elements created through JS - using document.createElement("div"); button.onclick = function(){ var mother= documnet.getEl...Id("parent"); for (var i = 0; i < 1;{ i++; var list = document.createElement("li"); mother.appendChild(list); list.innerHTML = someInput.value; var checkBox = document.createElement("input"); //imagine we put the attribute ... input type = checkbox; list.appendChild(checkBox); //inside the created lists is an input (checkbox); } } Now, how do I make sure that the checkbox is in front of the text (in front of list's text) The checkbox, then the text... // making a to-do list as you can tell.
3 Respuestas
+ 3
Ginfio
I haven't tested yet, but as I understand it, elements are by default rendered in the order of theirs presence. So I was thinking, add an <ul> or <ol> element to 'mother'. Next add checkbox followed by the <li> element to the <ul> or <ol>. Just an idea.
+ 2
Use a label. Append the checkbox then append a "label" element with your text.
+ 2
Try
button.onclick = function(){
var mother= document.getElementById("parent");
for (var i = 0; i < 1;i++) {
var list = document.createElement("li");
mother.appendChild(list);
var checkBox = document.createElement("input");
checkBox.type = "checkbox"
list.appendChild(checkBox);
list.innerHTML += "<label>value </label>";
}
}