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.

getAdjacentText method

Returns the adjacent text string.

Syntax

object.getAdjacentText(where)

Parameters

where [in]

Type: String

A String that specifies 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

Type: String

Returns the first adjacent text string.

Standards information

There are no standards that apply here.

Examples

This example uses the getAdjacentText method to find specific text.


<!DOCTYPE html>

<html>
<head>
  <title>getAdjacentText</title>
</head>
<body>
  This is the text before (beforeBegin).
  <p id="oPara">
    This is the text after (afterBegin).
    <strong>A few extra words.</strong>
    This is the text before (beforeEnd).
  </p>

  This is the text after (afterEnd).
  <select id="oSel">
    <option selected>beforeBegin</option>
    <option>afterBegin</option>
    <option>beforeEnd</option>
    <option>afterEnd</option>
  </select>
  <input type="button" value="Find text" onclick="fnFind()" />
  <script>
    function fnFind() {
      var oSel = document.getElementById('oSel');
      var sWhere = oSel.options[oSel.selectedIndex].text;
      console.log(document.getElementById('oPara').getAdjacentText(sWhere));
    }
  </script>
</body>
</html>

See also

a
abbr
acronym
address
applet
area
b
base
baseFont
bdo
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
comment
custom
dd
del
dfn
dir
div
dl
dt
em
embed
fieldSet
font
form
frame
frameSet
head
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=email
input type=file
input type=hidden
input type=image
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
ins
kbd
label
legend
li
link
listing
map
marquee
menu
nextID
object
ol
option
p
plainText
pre
q
s
samp
script
select
small
span
strike
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
tt
u
ul
var
xmp

 

 

Show:
© 2014 Microsoft