I have a function that will append a select-box with possibility to choose birthdate. What is the best way to achieve that?
When i run that script the append inside the for-loop is added after the closing-select. Is there any logic to the append, or is it not strict? I thought that the forloop had to be finished before it continued.
function addChildOption(){
if (counterOption < 3) {
$("#add-child").append("<select name=\"child" + counterOption + "\" form=\"register\">");
for(var i = year-15; i > 1900 ; i--){
$("#add-child").append("<option class=\"choose-year\" value=" + i + ">" + i + "</option>");
}
$("#add-child").append("</select>");
}
}
The result:
<select form="register" name="child1"></select>
<option class="choose-year" value="1999">1999</option>
<option class="choose-year" value="1998">1998</option>
<option class="choose-year" value="1997">1997</option>
etc....
$('#add-child select").append(...selectelement it has to be complete, you can't add the start tag and then the end tag. When you try to add the start tag, the browser will make a complete element out of it, so when you add the options they will end up after the select.