Test case details Title *
Description (Markdown syntax is allowed)
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)
Setup JS var html =
"<div> \
<div> \
<span>a</span> \
<span>b</span> \
<span>c</span> \
<span>d</span> \
</div> \
<div> \
<span>a</span> \
<span>b</span> \
<span>c</span> \
<span>d</span> \
</div> \
<div> \
<span>a</span> \
<span>b</span> \
<span>c</span> \
<span>d</span> \
</div> \
<div> \
<span>a</span> \
<span>b</span> \
<span>c</span> \
<span>d</span> \
</div> \
</div>" .replace (/[\s\r\n\t]+/g ,"" );
var div = document .createElement ("div" );
div.innerHTML = html;
function toVDOM (div ) {
var type = div.nodeType ;
if (type === 1 ) {
return {
nodeType : type,
nodeName : div.nodeName ,
childNodes : Array .prototype .map .call (div.childNodes , toVDOM)
};
} else if (type === 3 ) {
return {
nodeType : type,
nodeValue : div.nodeValue ,
childNodes : []
};
} else {
return {
nodeType : type
};
}
}
var vdiv = toVDOM (div);
function walk (node ) {
if (node.nodeType === 1 && node.childNodes .length )
for (var i = node.childNodes .length ; i--;) walk (node.childNodes [i]);
}
function walkDOM (node ) {
if (node.nodeType === 1 ) {
var current = node.firstChild ;
while (current) {
walkDOM (current);
current = current.nextSibling ;
}
}
}
Teardown JS