Home » Categories » JavaScript

How to change the text direction of an element?

$('input').keyup(function(){
    $this = $(this);
    if($this.val().length == 1)
    {
        var x =  new RegExp("[\x00-\x80]+"); // is ascii

        //alert(x.test($this.val()));

        var isAscii = x.test($this.val());

        if(isAscii)
        {
            $this.css("direction", "ltr");
        }
        else
        {
            $this.css("direction", "rtl");
        }
    }

});

Here's a working example.

Reference:
https://stackoverflow.com/questions/7770235/how-to-change-the-text-direction-of-an-element

Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
  • Icon Bookmark Bookmark Article (CTRL-D)
 
Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
How to hide image broken Icon using only CSS/HTML?
Viewed 814 times since Wed, Sep 30, 2020
Strip HTML Tags in JavaScript
Viewed 561 times since Sat, Oct 3, 2020
XMLHttpRequest.responseURL
Viewed 526 times since Wed, Sep 30, 2020
Get The Current Domain Name With Javascript (Not the path, etc.)
Viewed 595 times since Fri, Oct 2, 2020
Regex in Javascript to remove links
Viewed 538 times since Sat, Oct 3, 2020
Hidden image after redirect by check filename
Viewed 634 times since Wed, Sep 30, 2020
Check image width and height before upload with Javascript
Viewed 536 times since Mon, Sep 21, 2020