having problem with this code....want to change the every array elements color....when i add the document.body.innerHTML.style.color=color[i]; the code dosen't work.....could you guys just help me where i'm wrong...

+3 Praveen Sharma · August 6, 2015
<script>

var i;

var myArray = ["god","heaven","angel","hell","demon"];

var color = ["blue","yellow","red","green","purple"];

for(i=0;i<myArray.length;i++)

{

document.body.innerHTML.style.color=color;

document.write(myArray+"<br />");

}

</script>

Post a Reply

Replies

Oldest  Newest  Rating
0 Praveen Sharma · August 19, 2015
thanks Sochima Biereagu
and 
very thankful to sid wadhwa 
0 Praveen Sharma · August 19, 2015
but they are not in seprate color...
they all got the same color.....@Danny Ramirez
+1 Sid wadhwa · August 9, 2015
var i;
var myArray = ["god","heaven","angel","hell","demon"];
var color = ["blue","yellow","red","green","purple"];
for(i=0;i<myArray.length;i++)
{
document.write(myArray+"<br />");
 
document.body.style.color=color;
}
+1 Sochima Biereagu · August 7, 2015
the .innerHTML property can not be styled, it returns a string. I hope this is what you want tot achieve



var list = ["god","heaven","angel","hell","demon"], colors = ["blue","yellow","red","green","purple"];
colors.forEach(function(item, index){
var el = document.createElement("div");
document.body.appendChild(el);
el.style.color = item;
el.innerHTML = list[index];
});

//This should do the work

  • 1

Javascript

107,322 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators