Skip to content

Instantly share code, notes, and snippets.

@rozium
Created January 18, 2019 14:50
Show Gist options
  • Save rozium/5190bb0d0b7c43b973213bc005777364 to your computer and use it in GitHub Desktop.
Save rozium/5190bb0d0b7c43b973213bc005777364 to your computer and use it in GitHub Desktop.
Jabar Digital Service - Frontend - Javascript
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);
}
}
function decorateDivFunction(div) {}
// Example case.
document.body.innerHTML = `
<div id="a">
<div id="b">
</div>
</div>`;
appendChildren(decorateDivFunction);
console.log(document.body.innerHTML);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment