Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a textarea, change the direction of the current line from "rtl" to "ltr"

Tags:

jquery

css

I have a textarea with direction from right to left

#myTextarea
{
    direction: rtl; 
}

on an event, with jquery, i change the direction from left to right :

$('#myTextarea').css('direction', 'ltr');

this move the whole content of the textarea from right to left.

I want to move only the current line, and let the previous lines in their default direction.

Is there a way to achieve that ?

like image 253
Anas Avatar asked May 17 '12 08:05

Anas


People also ask

How to change LTR to rtl in html?

Add dir="rtl" to the html tag any time the overall document direction is right-to-left (RTL). This sets the default base direction for the whole document. All block elements in the document will inherit this setting unless the direction is explicitly overridden.

What is LTR and rtl?

For example, the en-US locale (for US English) specifies left-to-right. Most Western languages, as well as many others around the world, are written LTR. The opposite of LTR, RTL (Right To Left) is used in other common languages, including Arabic ( ar ) and Hebrew ( he ).

What is direction in CSS?

The direction CSS property sets the direction of text, table columns, and horizontal overflow. Use rtl for languages written from right to left (like Hebrew or Arabic), and ltr for those written from left to right (like English and most other languages).


2 Answers

This is not possible, the text direction can only apply to the entire textarea element, not the lines within it.

like image 86
Rory McCrossan Avatar answered Nov 14 '22 23:11

Rory McCrossan


You can try inserting '\u202E' characters at the beginning of the line, which will change the direction.

Also note that this is more of a hack than a real solution, it might not work in all browsers and on all platforms, I would try to think hard about if this is really what I want. Maybe you would be better off with a rich text editor.

Fiddle

like image 20
wrock Avatar answered Nov 15 '22 00:11

wrock