Skip to content

Instantly share code, notes, and snippets.

@mahpudeen
Created May 16, 2019 08:57
Show Gist options
  • Save mahpudeen/78fcfea53c11c9ca8af31e76fa2f1958 to your computer and use it in GitHub Desktop.
Save mahpudeen/78fcfea53c11c9ca8af31e76fa2f1958 to your computer and use it in GitHub Desktop.
function appendChildren(decorateDivFunction) {
var allDivs = document.getElementsByTagName("div");
var tes = allDivs.length;
for (var i = 0; i < tes; i++) {
var newDiv = document.createElement("div");
decorateDivFunction(newDiv);
allDivs[i].appendChild(newDiv);
}
}
// Example case.
document.body.innerHTML = `
<div id="a">
<div id="b">
</div>
</div>`;
//appendChildren(function(div) {});
console.log(document.body.innerHTML);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment