added extra test on foreach array
implemented $root.appendToDOM to replace root doc fragment with the new DOM element