Skip to content

Instantly share code, notes, and snippets.

@johnroyer
Created January 16, 2024 08:05
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 johnroyer/9bb2cee01f5f17090da18bbc80b61355 to your computer and use it in GitHub Desktop.
Save johnroyer/9bb2cee01f5f17090da18bbc80b61355 to your computer and use it in GitHub Desktop.
JavaScritp for() break after node removed
<html>
<body>
<ul id="target">
<li>1111</li>
<li>2222</li>
<li>3333</li>
<li>4444</li>
<li>5555</li>
</ul>
<script>
let nodes = document.getElementById('target').children
for(let index in nodes) {
console.log(nodes[index])
nodes[index].remove()
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment