Skip to content

Instantly share code, notes, and snippets.

@candraKriswinarto
Created May 16, 2019 02:21
Show Gist options
  • Save candraKriswinarto/f0699d0c686117593c358a8afdf9390a to your computer and use it in GitHub Desktop.
Save candraKriswinarto/f0699d0c686117593c358a8afdf9390a to your computer and use it in GitHub Desktop.
Frontend Engineer
function appendChildren(decorateDivFunction) {
var allDivs = document.querySelectorAll("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