Created
August 12, 2019 16:36
-
-
Save jutionck/168a473c22319656eff6ccb16d0e4f6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function appendChildren(decorateDivFunction) { | |
//mengganti getElementsByTagName dengan querySelectorAll | |
var allDivs = document.querySelectorAll("div"); | |
// loop based on allDivs length | |
for (var i = 0; i < allDivs.length; i++) { | |
// create new element div | |
var newDiv = document.createElement("div"); | |
decorateDivFunction(newDiv); | |
// append new div into curent div | |
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