(function () {
var elems = document.getElementsByTagName("*");
for (var i = 0, j = 0; i < elems.length; i++) {
if (elems[i].id == "name") {
if (++j % 5 === 4) {
var div = document.createElement("DIV");
div.id = "foo";
elems[i].parentNode.insertBefore(elems[i], elems[i].nextSibling);
}
}
}
})();