Created
January 18, 2019 10:26
-
-
Save dhanyn10/9b4fc6cec1a4a57ac90aa50ca185e65f to your computer and use it in GitHub Desktop.
Jawaban test code:
This file contains hidden or 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) { | |
var allDivs = document.getElementsByTagName("div"); | |
divlength = allDivs.length; | |
for (var i = 0; i < divlength; 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); |
This file contains hidden or 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
<!-- jawaban langsung dari browser, diubah sedikit dengan teknik beautifier agar mudah dibaca --> | |
<!-- test dengan 2 level html --> | |
<div id="a"> | |
<div id="b"> | |
<div></div> | |
</div> | |
<div></div> | |
</div> | |
<!-- test dengan 5 level html --> | |
<div id="a"> | |
<div id="b"> | |
<div id="c"> | |
<div id="d"> | |
<div id="e"> | |
<div></div> | |
</div> | |
<div></div> | |
</div> | |
<div></div> | |
</div> | |
<div></div> | |
</div> | |
<div></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment