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 ID: 31
Created On: Sat, Sep 26, 2020 at 1:51 AM
Last Updated On: Sat, Sep 26, 2020 at 1:51 AM
Authored by: Saeed Nobakht [[email protected]]

Online URL: https://www.navel.ir/article/how-to-change-the-text-direction-of-an-element-31.html