please help me I don't know create dataset with use checkbox,, this is my source code:
const isCompleted = document.querySelector('[data-input-Book-IsComplete]:checked');
how should it be...? Thank you
please help me I don't know create dataset with use checkbox,, this is my source code:
const isCompleted = document.querySelector('[data-input-Book-IsComplete]:checked');
how should it be...? Thank you
You need to quote the value of the data attribute.
const isCompleted = document
.querySelector('input[data-input="Book-IsComplete"]:checked')
.checked;
console.log(isCompleted); // true
<input type="checkbox" data-input="Book-IsComplete" checked />
if you want to check the dataset, you can try the following:
const isCompleted = [...document.querySelectorAll('input[type="checkbox"]')]
.find(checkbox => checkbox.dataset.input === 'Book-IsComplete')?.checked ?? false;
console.log(isCompleted); // true
<input type="checkbox" data-input="Book-IsComplete" checked />