Skip to content

Instantly share code, notes, and snippets.

@kamalhm
Created August 10, 2019 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamalhm/28ee3862a81686fe4d188b9bd44310d3 to your computer and use it in GitHub Desktop.
Save kamalhm/28ee3862a81686fe4d188b9bd44310d3 to your computer and use it in GitHub Desktop.
FE_Javascript
function appendChildren(decorateDivFunction) {
var allDivs = [...document.getElementsByTagName("div")];
for (var i = 0; i < allDivs.length; 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