-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmassAddOptionsQuick.js
More file actions
21 lines (18 loc) · 867 Bytes
/
massAddOptionsQuick.js
File metadata and controls
21 lines (18 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// DocumentFragment allows to add elements all at once without repeatedly hitting the DOM with updates
function populateStartTimes() {
let startTime = document.getElementById( 'startTimeSelect' );
// prepare list of options without affecting the live DOM
var amOptionList = new DocumentFragment(), pmOptionList = new DocumentFragment();
for( var i = 0; i < 12; i++ ) {
let amOption = document.createElement( "option" );
amOption.text = ( i == 0 ? 12 : i ) + " AM";
amOptionList.appendChild( amOption );
let pmOption = document.createElement( "option" );
pmOption.text = ( i == 0 ? 12 : i ) + " PM";
pmOptionList.appendChild( pmOption );
}
// mass add the options to the DOM
startTime.appendChild( amOptionList );
startTime.appendChild( pmOptionList );
}
populateStartTimes();