DHTML Methods
Retrieves the parent element for the given text range. The parent element is the element that completely encloses the text in the range.
oElement = TextRange.parentElement ( )
Returns an element object if successful, or null otherwise.
If the text range spans text in more than one element, this method returns the smallest element that encloses all the elements. When you insert text into a range that spans multiple elements, the text is placed within the parent element rather than in any of the contained elements.
This feature might not be available on non-Win32® platforms. See the Microsoft® Knowledge Base for the latest information on Internet Explorer® cross-platform compatibility.
The following JScript™ ( compatible with ECMA-262 language specification ) example retrieves the parent element for the text range created from the current selection and displays the tag name of the element.
var sel = document.selection;
var rng = sel.createRange ( );
var el = rng.parentElement ( );
alert ( el.tagName );
TextRange