parentElement Method

MS Office DHTML, HTML & CSS

 
Click to return to the DHTML, HTML & CSS home page    
open Method     pasteHTML Method     DHTML Methods    

parentElement Method


Retrieves the parent element for the given text range.

Syntax

oElement = TextRange.parentElement()

Return Value

Returns an element object if successful, or null otherwise.

Remarks

The parent element is the element that completely encloses the text in the range.

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 in the parent element rather than in any of the contained elements.

This feature might not be available on non-Win32® platforms. For the latest information about Internet Explorer cross-platform compatibility, see article q172976Internet Link Non-MSDN link in the Microsoft Knowledge Base.

Example

This example uses the parentElement method to retrieve the parent element for the text range created from the current selection, and display the tag name of the element.

<SCRIPT LANGUAGE="JScript">
var sel = document.selection;
var rng = sel.createRange();
var el = rng.parentElement();
alert(el.tagName);
</SCRIPT>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
TextRange

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.