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) <script src ="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" > </script >
<div id ="root" > </div >
<script >
if (!Array .prototype .indexOf ) {
Array .prototype .indexOf = function (item ) {
var len = this .length >>> 0 ;
for (var i = 0 ; i < len; i++) {
if (this [i] === item) {
return i;
}
}
return -1 ;
};
}
var data = (function ( ) {
var elements = [];
var storage = [];
return function (el, key, value ) {
var i = elements.indexOf (el);
if (typeof value != "undefined" ) {
if (i == -1 ) {
i = elements.length ;
elements[i] = el;
storage[i] = {};
}
storage[i][key] = value;
} else if (storage[i]) {
return storage[i][key];
}
};
})();
var data2 = (function ( ) {
var storage = {};
var counter = 1 ;
return function (el, key, value ) {
var uid = el.uniqueID || (el.uniqueID = counter++);
if (typeof value != "undefined" ) {
storage[uid] || (storage[uid] = {});
storage[uid][key] = value;
} else if (storage[uid]) {
return storage[uid][key];
}
};
})();
var MAXDEPTH = 2 ;
var dummy = document .createElement ("div" );
var total = 0 ;
function createBranch (root, depth ) {
depth = depth ? depth + 1 : 1 ;
for (var i = 0 ; i < 10 ; i++) {
total++;
var el = dummy.cloneNode (false );
el.id = "elem" + total;
root.appendChild (el);
if (depth < MAXDEPTH ) {
createBranch (el, depth);
}
}
}
var root = document .getElementById ("root" );
createBranch (root);
var elems = root.getElementsByTagName ("div" );
var len = elems.length ;
var ret;
</script >
Setup JS
Teardown JS