Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

html table cell color based on value

<!--Please give a thumbs up if this was helpfull-->

<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<script type="text/javascript">

$(document).ready(function(){
    $('#table_id td.y_n').each(function(){
        if ($(this).text() == 'N') {
            $(this).css('background-color','#f00');
        }
    });
});

</script>

</head>
<body>

<table id="table_id">
 <tr><th>Question</th><th>Y/N?</th></tr>
 <tr><td>I am me.</td><td class="y_n">Y</td></tr>
 <tr><td>I am him.</td><td class="y_n">N</td></tr>
 <tr><td>I am not sure.</td><td class="y_n">Y</td></tr>
 <tr><td>This is a table.</td><td class="y_n">Y</td></tr>
</table>

</body>
</html>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #html #table #cell #color #based
ADD COMMENT
Topic
Name
1+7 =