Last active
December 31, 2015 01:09
-
-
Save cnocon/7911589 to your computer and use it in GitHub Desktop.
Blog post on javascript iteration
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> | |
<title>Looping in Javascript</title> | |
<script async src="blogpost.js"></script> | |
</head> | |
<body> | |
<section> | |
<h2>Here is our 1st section element.</h2> | |
</section> | |
<section> | |
<h2>Here is our 2nd section element.</h2> | |
</section> | |
<section> | |
<h2>Here is our 3rd section element.</h2> | |
</section> | |
</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
window.onload= function(){ | |
var styleSet = { | |
boxShadow: "0 1px 3px rgba(0,0,0,0.5)", | |
textShadow: "1px 1px #000", | |
backgroundColor: "#ffffff", | |
padding: "1em", | |
margin: "2em 0" | |
} | |
var elements = document.getElementsByTagName('section'); | |
//console.log(elements.length) | |
//console.log(elements[3]) | |
// failed with for (var e in elements) {} | |
for (e = 0; e < elements.length; e++) { | |
//console.log("hello" + elements[e]) | |
for (var s in styleSet) { | |
//console.log(s) | |
//console.log(elements[e]) | |
elements[e].style[s] = styleSet[s] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment