Reputation: 27
I try to change the background color of listview
in html using color
variable in html but its no working but when am assign simple background-color:red;
then its working, but I want to change the color using color
variable.
<ul>
<script>
var d = new Date();
var d = new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
var color="red";
var day=d.getDay();
for(var i=0;i<7;i++)
{
if(day==7)
day=0;
document.write("<li style='background-color:'"+color+"';'>");
document.write(weekday[day]); document.write("</li>");
day++;
}
</script>
</ul>
}
</script>
</ul>
</body>
</html>
Upvotes: 0
Views: 308
Reputation: 57095
Don't wrap color in quotes.
document.write("<li style='background-color:" + color + ";'>");
// remove single quote here ^ ^
Here is the working link Demo
Upvotes: 1
Reputation: 32581
You don't need to quote "red"
Change
document.write("<li style='background-color:'"+color+"';'>");
//Single quote removed ^ ^
to
document.write("<li style='background-color:"+color+";'>");
Upvotes: 0
Reputation: 1050
Your code is incorrect.Change this line-
document.write("<li style='background-color:"+color+";'>");
This is tested and working.
Upvotes: 0
Reputation: 15393
Remove the extra one single quote near the color variable
document.write("<li style='background-color:"+color+";'>");
Upvotes: 0