<!DOCTYPE html>
<html>
<body>

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

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    document.getElementById("myP").dir = "rtl";
}
</script>

</body>
</html>