JS implements a method to control the alignment of the contents of a specified cell in a table

  • 2020-05-19 04:12:08
  • OfStack

This article demonstrates an example of how JS can control the content alignment of a specified cell in a table. Share with you for your reference. The details are as follows:

The code below controls the right-alignment of the contents of the table cells


<!DOCTYPE html>
<html>
<head>
<script>
function alignCell()
{
document.getElementById('td1').align="right";
}
</script>
</head>
<body>
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td id="td1">Peter</td>
<td id="td2">Griffin</td>
</tr>
</table>
<br>
<input type="button" onclick="alignCell()" value="Align cell" />
</body>
</html>

I hope this article has been helpful to your javascript programming.


Related articles: