I'm using pug to generate a list of radio buttons using a while
loop:
- var n = 0;
while n < 11
input(type="radio", name="cb", id="cb"+n, value=n)
label(for="cb"+n) #{n++}
The problem is that in this way none is marked by default and I want the first one to be marked by default and I do not know how it would be done.
At the moment I have removed the first element from the list and I have put it out with a checked=""
so that it appears marked by default:
input(type="radio", name="cb", checked="", id="cb0", value=0)
label(for="cb0") 0
- var n = 1;
while n < 11
input(type="radio", name="cb", id="cb"+n, value=n)
label(for="cb"+n) #{n++}
But, although it works, this seems inefficient because I'm repeating code and, if I want to make changes, I have to do it in two different places.
Is there any way to make the first radio button have that additional attribute without needing to get it out of the loop?