In a loop, I want to add a selected attribute to the option element if it fits my condition.
${list.map((item, i) => this.$h`
<option value="${item}" ${i === 0 && "selected"}>Text</option>`)}
It doesn’t work this way.
In a loop, I want to add a selected attribute to the option element if it fits my condition.
${list.map((item, i) => this.$h`
<option value="${item}" ${i === 0 && "selected"}>Text</option>`)}
It doesn’t work this way.
I found the solution.
(Conditional element attributes not working using templates - #2 by nolimits4web)
${list.map((item, i) => this.$h`
<option value="${item}" selected=${i === 0}>Text</option>`)}
If it is undefined it won’t be rendered