Js If Statement - Innerhtml
function colorize(){ for(i = 1; i<=8; i++) { var id = document.getElementById('op' + i); var stat = id.innerHTML; document.write(stat + ' ');
Solution 1:
If stat.length
always equals 1:
if(stat[0]=='1'){
If all you are looking for is a 1
in stat
:
if(stat.match(/1/)){//contains a 1, may contain more
Solution 2:
functioncolorize(){
for(i = 1; i<=8; i++)
{
var id = document.getElementById('op' + i);
var stat = id.innerHTML;
document.write(stat + " ");
if(stat == "1")
{
id.innerHTML = "<div style='background:#00FF00; width: 20px; height: 20px; border-radius: 15px;'></div>";
}
else{
id.innerHTML = "<div style='background:#FF0000; width: 20px; height: 20px; border-radius: 15px;'></div>";
}
}
}
Post a Comment for "Js If Statement - Innerhtml"