Windows Dev Center

EN
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

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
address
area
b
base
bdo
blockQuote
body
br
button
caption
cite
code
col
colGroup
comment
custom
dd
del
dfn
div
dl
dt
em
embed
fieldSet
form
frame
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
map
menu
object
ol
option
p
pre
q
s
samp
script
select
small
span
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
u
ul
var

 

 

Anzeigen:
© 2015 Microsoft