Preparation Code Preparation HTML (this will be inserted in the <body>
of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <div id ="container" > </div >
Setup JS var container = document .getElementById ("container" ),
obj = {
one : 1 ,
two : 2 ,
three : {
four : 4 ,
five : "five" ,
six : {
seven : [ 8 , 9 , 10 , 11 , 12 ],
thirteen : [ 14 , 15 , 16 , 17 ]
},
eighteen : 18
},
nineteen : "nineteen"
}
function doSomethingAndWriteToLog ( ) {
for (var i = 0 ; i < 1000 ; i++) {
var div = document .createElement ("DIV" );
var span = document .createElement ("SPAN" );
div.appendChild (span);
container.appendChild (div);
console .log (i);
}
}
function doSomethingAndWriteObjToLog ( ) {
for (var i = 0 ; i < 1000 ; i++) {
var div = document .createElement ("DIV" );
var span = document .createElement ("SPAN" );
div.appendChild (span);
container.appendChild (div);
console .log (obj);
}
}
function justDoSomething ( ) {
for (var i = 0 ; i < 1000 ; i++) {
var div = document .createElement ("DIV" );
var span = document .createElement ("SPAN" );
div.appendChild (span);
container.appendChild (div);
}
}
function doSomethingAndLogWhenDone ( ){
for (var i = 0 ; i < 1000 ; i++) {
var div = document .createElement ("DIV" );
var span = document .createElement ("SPAN" );
div.appendChild (span);
container.appendChild (div);
}
console .log ("Completed DOM operations!" );
}
Teardown JS
container.innerHTML = "" ;