Skip to content

Instantly share code, notes, and snippets.

@akatgelar
Created January 21, 2019 03:00
Show Gist options
  • Save akatgelar/82a501da49695e1459ed9af16c7282cd to your computer and use it in GitHub Desktop.
Save akatgelar/82a501da49695e1459ed9af16c7282cd to your computer and use it in GitHub Desktop.
function appendChildren(decorateDivFunction) {
var allDivs = document.getElementsByTagName("div");
var len = allDivs.length;
for (var i = 0; i < len; 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