Thursday, 12 September 2013

for loop an argument in function

for loop an argument in function

I was doing this code but it will take time because it will be h1 up until
h24 so i decided to use a for loop but i don't know how..
this is my original code
<script>
function hover(h1,h2,h3,h4){
document.getElementById(h1).style.backgroundColor="orange";
document.getElementById(h2).style.backgroundColor="orange";
document.getElementById(h3).style.backgroundColor="orange";
document.getElementById(h4).style.backgroundColor="orange";
}
</script>
and i want to replace it something like this
function hover( for(i = 1; i<=24; i++){
document.write("h"+i+",");
})
but there is an error.. Please help me out.. Thank you

No comments:

Post a Comment