Цель - добавить текст после элемента флажка в документе
Проблема - в настоящее время текстовое поле не отображается в документе.Тем не менее, он появляется, если я установил todoLi.appendChild(checkbox)
после todoLi.textContent = todo.todoText
, но это не мое желаемое состояние.Я хочу, чтобы флажок добавлялся перед .textcontent
из <li>
Код
const todoList = {
todos: [],
addTodo: function(todoText){
this.todos.push({
todoText: todoText,
completed: false
})
}
}
const views = {
displayTodos: function(){
const todosContainer = document.querySelector('#todosContainer')
if(todoList.todos.length === 0){
const message = document.createElement('p')
message.textContent = 'There are currently no todos'
todosContainer.appendChild(message)
}else{
todoList.todos.forEach(function(todo){
const checkbox = document.createElement('input')
const todoLi = document.createElement('li')
checkbox.setAttribute('type', 'checkbox')
todoLi.appendChild(checkbox)
todoLi.textContent = todo.todoText
todosContainer.appendChild(todoLi)
})
}
}
}
views.displayTodos()
<ul id="todosContainer"></ul>