Re: Detecting direction of text with JavaScript

The function window.getComputedStyle( element ) should help. It
returns an object, which is supposed to have the direction property,
which will correspond to the computed CSS direction property.

The question is how do you get the element.

If the inner span has the id 'inner-span', then you can do something like this:

window.getComputedStyle( document.getElementById( 'inner-span' ) ).direction

If you are using jQuery, then you'll have to use the method .get() on
the jQuery object to get the DOM element object, which you can pass to
window.getComputedStyle.

Hope it helps.

--
Amir Elisha Aharoni · אָמִיר אֱלִישָׁע אַהֲרוֹנִי
http://aharoni.wordpress.com
‪“We're living in pieces,
I want to live in peace.” – T. Moore‬


2013/3/22 Richard Ishida <ishida@w3.org>:
> Does anyone know how I would detect the direction of the content of the span
> element in the following?
>
> <p dir=rtl>RTLTEXT <span>MORE RTLTEXT</span></p>
>
> Cheers,
> RI
>
>
> --
> Richard Ishida, W3C
> http://rishida.net/
>

Received on Friday, 22 March 2013 13:03:25 UTC