I am writing the function below to create a task in a to-do list app (using input) but the function is not creating one

Viewed 16

this is the function I have written which will be executed when you click the button('create'). but somehow it is not creating the element. It gets the value of the text written in the input tag using value attribute.

function create() {

let text1 = document.getElementById('input').value;
if (text1.trim() == "" || text1.trim() == null){
    return false;
}

else{
    document.getElementById("input").value = "";
}

let li = document.createElement('li');

li.setAttribute('class', 'todo');

document.getElementById('list').appendChild(li);
let p1 = document.createElement('p');
p1.setAttribute('class', 'text');

let teks = document.createTextNode(text1);
p1.appendChild(teks);
li.appendChild(p1);

let btn1 = document.createElement('button');
btn1.innerHTML = 'Edit';
btn1.setAttribute('class', 'buttons1');
btn1.setAttribute('onclick', 'edit()')

let btn2 = document.createElement('button');
btn2.innerHTML = 'Delete';
btn2.setAttribute('class', 'buttons2');
btn1.setAttribute('onclick', 'delete()')
li.appendChild(btn1);
li.appendChild(btn2);

}

0 Answers
Related