+ 1
Let's fix this bug together š„²
I'm trying to be checked a box when ${element.completed} has true value and unchecked when it has false value. One more thing is that I'm using API to show content on webpage so that I'm using javascript for that. hope you get my point...... https://www.sololearn.com/post/1690845/?ref=app
4 Answers
+ 3
Davinder Kumar
You were on the right track just need to put checked inside of the brackets and use && operator
<td><input type='checkbox' ${element.completed && "checked"}></td>
+ 3
Davinder Kumar
var checked = ''
if (element.completed) {
checked = 'checked';
}
<input type = 'checkbox' ${checked} />
+ 2
Your ternary operation has no `else` block, but then again, adding an `else` block didn't seem to help, except where the ternary condition and its results is moved within the {} guard.
`<td><input type='checkbox' ${element.completed ? 'checked' : ''}/></td>`;