Javascript DOM HTML Element dir Property get

Introduction

Get the text direction of a <p> element:

var x = document.getElementById("myP").dir;

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" dir="rtl">Click the button to display my text direction.</p>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w w w.  j a  v  a 2 s  . c o  m
  var x = document.getElementById("myP").dir;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related