this is my code:
function newTodo() {
const text = prompt('What needs to be done?').trim();
if (!!text) {
id += 1;
const todoId = 'todo' + id;
// checkbox
const todoCheckbox = document.createElement('input');
todoCheckbox.type = 'checkbox';
todoCheckbox.id = todoId;
todoCheckbox.classname = classNames.TODO_CHECKBOX;
todoCheckbox.setAttribute('onclick', `handleCheck(${todoId})`);
...
} else {
alert('Please enter a valid todo');
}
}
function handleCheck(todoId) {
console.log('checked!', todoId);
}
but handleClick is logging the html element the function is attached to:
<input type="checkbox" id="todo2" onclick="handleCheck(todo2)">
I wanted to log the id only, so i am expecting it to be:
todo2
what am i doing wrong?
handleClickyou meanhandleCheck?<input type="checkbox" id="todo2" onclick="handleCheck('todo2')">