Created
April 8, 2015 12:47
-
-
Save NetanelBasal/77c9bde155f3cc91192c to your computer and use it in GitHub Desktop.
loop children dom
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div> | |
<ul> | |
<li><a href="" class='first'>1</a></li> | |
<li><a href="">2</a></li> | |
<li><a href="">3</a></li> | |
<li><a href="">4</a></li> | |
</ul> | |
</div> | |
</body> | |
</html> |
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
loopChildren(document.querySelector('div')); | |
function loopChildren(parent) { | |
var i = 0; | |
while(parent.children[i]) { | |
if(parent.children[i].className === 'first') { | |
parent.children[i].style.color = 'red'; | |
} | |
loopChildren(parent.children[i]); | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment