moveToElementText method (Internet Explorer)

Switch View :
ScriptFree
moveToElementText method

Moves the text range so that the start and end positions of the range encompass the text in the given element.

Syntax

object.moveToElementText(element)

Standards information

There are no standards that apply here.

Parameters

element [in]

Type: IHTMLElement

Object that specifies the element object to move to.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

This feature might not be available on non-Microsoft Win32 platforms.

 

 

Send comments about this topic to Microsoft

Build date: 2/14/2012

Community Content

-Munawwar-
Example Snippet: selectAllChildren

moveToElementText doesn't actually highlight the text on screen. But it internally sets the start and end positions to element's first character (of the first text node) and last character (of the last text node). [Note: It doesn't matter where the first and last text node comes within the element. It just selects it all.]

After calling 'moveToElementText' you could call the 'select' function to highlight the selected text on screen.

So if I were to bring the HTML5 range.selectAllChildren method ( http://msdn.microsoft.com/en-us/library/ff975180(v=VS.85).aspx ) to IE8, I would do:

var range=document.selection.createRange();
range.moveToElementText(element);
range.select(); //This line does the highlighting

For cross-browser functionality (and support with IE9):

function selectAllChildren(element) {
if(window.getSelection) { //W3C Selection Object. Firefox/Chrome/Opera/IE9
window.getSelection().selectAllChildren(element);
} else if(document.selection) { //IE8
var range=document.selection.createRange();
range.moveToElementText(element);
range.select();
}
}

zxpradeep
Required example
Here should be an appropriate example to clear it's implemention.