Set text alignment in Javascript

Description

The following code shows how to set text alignment in Javascript.

Example


<html>
<head>
<script type="text/javascript">
  function bigger() {<!--  ww w  .j av a2s .c om-->
    var div = document.getElementById("div1");
    div.style.textAlign = "justify";
  }

  function smaller() {
    var div = document.getElementById("div1");
    div.style.textAlign = "left";
  }
</script>

</head>
<body>
  <a href="javascript:bigger();">bigger</a>
  <a href="javascript:smaller();">smaller</a>
  <div id="div1">
    <p>p1</p>
    <p>p2</p>
  </div>
</body>
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window