I am trying to
- Retrieve 2 columns from MySQL and display them in HTML table
- When clicked on Name which is in the table header i want to change the color of all the contacts.
what I hv done-
callin a javascript on tableRows
id to change color,but it only changes the the color of 1st row.
<?php
while($row_color_test = mysql_fetch_assoc($result_color_test))
{
?>
<tr id="tableRows">
<td><?php echo $row_color_test['name'] ; ?></td>
<td><?php echo $row_color_test['phone']; ?></td>
</tr>
<?php
}
?>
Javascript Function
function changecolor()
{
document.getElementById("tableRows").style.color="red";
}
any idea why it happening although all the rows are dynamically created by while loop so all hv the same id and therefore,CSS rule sud apply on them.
Or is there a better way to do it??I hv to use Javascript only