Javascript Style How to - Set text alignment








Question

We would like to know how to set text alignment.

Answer


<!--from   w  w w .  java2 s. c  o  m-->
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<body onload="document.getElementById('div1').style.textAlign='center';">
  <div id='div1'>content</div>
</body>
</body>
</html>

The code above is rendered as follows: