This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

getAdjacentText

Summary

Non standard. Gets a text from a given location around the edges of the element.

Method of dom/Elementdom/Element

Syntax

var text = element.getAdjacentText(where);

Parameters

where

Data-type
String

Where the text is located by using one of the following values.

beforeBegin

Text is returned immediately before the element.

afterBegin

Text is returned after the start of the element but before all other content in the element.

beforeEnd

Text is returned immediately before the end of the element but after all other content in the element.

afterEnd

Text is returned immediately after the end of the element.

Return Value

Returns an object of type StringString

The first adjacent text.

Examples

This example uses the getAdjacentText method to find specific text.

<script>
function findText(){
        var select = document.getElementById("sel");
    var whereToFind = select.options[select.selectedIndex].textContent;
    console.log(document.getElementById("para").getAdjacentText(whereToFind));
}
</script>
This is the text before (beforeBegin).
<p id="para">
This is the text after (afterBegin).
<b>A few extra words.</b>
This is the text before (beforeEnd).
</p>
This is the text after (afterEnd).
<select id="sel">
<option selected="selected">beforeBegin</option&gtl
<option>afterBegin</option&gtl
<option>beforeEnd</option&gtl
<option>afterEnd</option&gtl
</select>
<input type="button" value="Find text" onclick="findText()">

Attributions