I want to highlight color to many rows if its date value passes my condition as below code
I'm retrieving from_date and to_date from database by using foreach() in php and I will extract it into rows of table and I want to highlight with red color to some rows of table if from_date and to_date value pass my condition as below javascript
But I don't know how to do it with javascript code to find all id selector of html and set its color to red,black,blue if from_date and to_date passes condition.
<table>
<tr class="highlight">
<td>ID:</td>
<td id="from">From Date: 2014-11-28</td>
<td id="to">To Date: 2014-11-30</td>
</tr>
<tr class="highlight">
<td>ID:</td>
<td id="from">From Date: 2014-11-28</td>
<td id="to">To Date: 2014-11-28</td>
</tr>
<tr class="highlight">
<td>ID:</td>
<td id="from">From Date: 2014-11-28</td>
<td id="to">To Date: 2014-11-28</td>
</tr>
<tr class="highlight">
<td>ID:</td>
<td id="from">From Date: 2014-11-28</td>
<td id="to">To Date: 2014-12-01</td>
</tr>
<tr class="highlight">
<td>ID:</td>
<td id="from">From Date: 2015-01-01</td>
<td id="to">To Date: 2015-01-30</td>
</tr>
</tabl>
As above html code I want to use array in javascript to check all id html selector to check its from_date and to_date value and set red color to highlight class (class="highlight") by condition.
<script>
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var from_day = document.getElementById("from");
var to_day = document.getElementById("to");
var highlight = [];
var get_from_day = new Date(from_day);
var get_to_day = new Date(to_day);
var i = document.getElementById();
if(get_from_day.getTime() == get_to_day.getTime()){
highlight[] = "red";
}
if(get_from_day.getTime() > get_to_day.getTime()){
highlight[] = "blue";
}
if(get_to_day.getTime() == today.getTime()){
highlight[] = "black";
}else{
if(highlight){
for(i=0;i<=;i++){
document.getElementById("highlight").style.background-color = highlight;
}
}
}
</script>
Thanks advance for help