loop through highlighted text.
<p>I have a question on a javascript 
i need to loop through user selection(highlighted text) and change the text direction from trl or ltr .
here what i did :</p>

<pre><code>this._execCom("FormatBlock",'&lt;div&gt;');
var node = null;
if (this.area.contentWindow.getSelection) {
    node = this.area.contentWindow.getSelection().anchorNode.parentNode;

}
else if (this.area.contentWindow.document.selection) {
    var range = this.area.contentWindow.document.selection.createRange();
    if (range) {
        node = range.parentElement();
    }
    var walker=this.area.contentWindow.document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, null, false);
    while (walker.nextNode())
    {
        x=walker.currentNode.tagName;
        if( x == 'DIV')
            walker.currentNode.style.direction="ltr";
    }
</code></pre>

<p>this changes the direction for all divs even if they are within the highlighted text or not and i need the changes to be done on the user selection only .</p>

<p>can you help me please .</p>

<p>many thanks</p>
