Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

parentElement method

Retrieves the parent element for the given text range.

Syntax

var retval = TextRange.parentElement();

Parameters

This method has no parameters.

Return value

Type: IHTMLElement

Returns the parent element object if successful, or null otherwise.

Standards information

There are no standards that apply here.

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-Microsoft Win32 platforms.

Examples

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>
  var sel = document.selection;
  var rng = sel.createRange();
  var el = rng.parentElement();
  alert(el.tagName);
</script>

See also

TextRange

 

 

Show:
© 2015 Microsoft