Forum Moderators: open
<div id="myDiv">
<a href="http://www.google.com">Google</a> <a href="http://www.yahoo.com">Yahoo</a> <a href="http://www.live.com">Live</a>
<a href="http://www.google.com">Google</a> <a href="http://www.yahoo.com">Yahoo</a> <a href="http://www.live.com">Live</a>
<a href="http://www.google.com">Google</a> <a href="http://www.yahoo.com">Yahoo</a> <a href="http://www.live.com">Live</a>
</div>
<script type="text/javascript">
window.onload = function() {
var whatColor, whatSize;
var myColors = ["Red","Green","Blue","Pink","Yellow","Purple","Orange"];
var fontMin = 10;
var fontMax = 40;
var div1 = document.getElementById("myDiv");
var links = div1.getElementsByTagName("a")
for(i=0;i<links.length;i++) {
whatColor = Math.floor(Math.random() * myColors.length);
whatSize = Math.floor(Math.random() * (fontMax - fontMin + 1)) + fontMin;
links[i].style.color = myColors[whatColor];
links[i].style.fontSize = whatSize + "px";
}
}
</script>
<div id="myDiv">
:
</div>
<script type="text/javascript">
function styleLinks() {
// Rest of function
:
:
}
styleLinks(); // Call the function
</script>
Providing the function is called after your links in the document, it should be OK. To keep your page less cluttered, you could put your JavaScript before your closing BODY tag - after all your markup.