Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Изменить цвет столбца в зависимости от условия (https://javascript.ru/forum/dom-window/34944-izmenit-cvet-stolbca-v-zavisimosti-ot-usloviya.html)

Prophet_ 25.01.2013 11:42

Изменить цвет столбца в зависимости от условия
 
Всем привет.
Есть фрагмент HTML:
<th scope='col' class='dataValueRead cellCont ' style='width:86px;'><div class='divCont'><span class='wspan'></span><div class='cellIn'><input type="hidden" name="PTimesheetList3colWidthCache3" id="PTimesheetList3colWidthCache3" value="" /><nobr>                   Пн 21.01.13          </nobr></div></div></th>


нужна javascript вставка чтобы закрасить бэкграунд этого элемента.

alert('Hello!');//просто дебажный алерт для проверки
var Color1= document.getElementById('PTimesheetList3colWidthCache3');
Color1.style.color = "green"; 

function UpdateColumnColor() 
{
    var Color1 = document.getElementById('PTimesheetList3colWidthCache3');
    Color1.style.color = "green"; 
}


подскажите, что не так??

danik.js 25.01.2013 14:38

Так ведь PTimesheetList3colWidthCache3 - это скрытый элемент, он не отображается, какой смысл менять цвет его текста?

<th scope='col' class='dataValueRead cellCont ' style='width:86px;'>
    <div class='divCont'><span class='wspan'></span>
        <div class='cellIn'><input type="hidden" name="PTimesheetList3colWidthCache3" id="PTimesheetList3colWidthCache3" value="" /><nobr>                   Пн 21.01.13          </nobr>
            
        </div>
    </div>
</th>
<script>
    (function(){
        var cell = document.getElementById('PTimesheetList3colWidthCache3').parentNode;
        cell.style.color = "green"; 
        
        UpdateColumnColor = function() 
        {
            cell.style.color = "green"; 
        }
    })();
</script>


Часовой пояс GMT +3, время: 10:44.