A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/TextRange/parentElement below:

parentElement ยท WebPlatform Docs

parentElement Summary

Retrieves the parent element for the given text range.

Method of dom/TextRangedom/TextRange

Syntax
var parentNode = textRange.parentElement();
Return Value

Returns an object of type DOM NodeDOM Node

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

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

Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4