หากต้องการกำหนดทิศทางของข้อความ ให้ใช้ ทิศทาง คุณสมบัติด้วย JavaScript ตั้งค่า rtl สำหรับขวาไปซ้ายหรือ ltr สำหรับทิศทางข้อความจากซ้ายไปขวา
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อกำหนดทิศทางของข้อความด้วย JavaScript -
<!DOCTYPE html>
<html>
<body>
<h1 id="myID">Heading 1</h1>
<p>Click below to set the direction of heading to Left-to-right</p>
<button type="button" onclick="display()">Click to change the direction</button>
<script>
function display() {
document.getElementById("myID").style.direction = "rtl";
}
</script>
</body>
</html>