(0) exportieren Drucken
Alle erweitern
EN
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

insertAdjacentHTML method

Inserts the given HTML text into the element at the location.

Syntax

object.insertAdjacentHTML(where, html)

Parameters

where [in]

Type: String

String that specifies where to insert the HTML text, using one of the following values:

beforeBegin

Inserts html immediately before the object.

afterBegin

Inserts html after the start of the object but before all other content in the object.

beforeEnd

Inserts html immediately before the end of the object but after all other content in the object.

afterEnd

Inserts html immediately after the end of the object.

html [in]

Type: String

String that specifies the HTML text to insert. The string can be a combination of text and HTML tags. This must be well-formed, valid HTML or this method will fail.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information

There are no standards that apply here.

Remarks

If the text contains HTML tags, the method parses and formats the text as it is inserted.

You cannot insert text while the document is loading. Wait for the onload event to fire before attempting to call this method.

When using the insertAdjacentHTML method to insert script, you must include the DEFER attribute in the script element.

Examples

This example demonstrates the insertAdjacentHTML method.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/insertscript_1.htm


<!DOCTYPE html>

<html>
<head>
  <title>insertAdjacentHTML</title>
</head>
<body>
  <div id="firstDiv">First <strong>div</strong></div>  
  <!--THE SCRIPT INSERTS <div id="secondDiv">Second <strong>div</strong></div> RIGHT HERE. -->
  <script>
    var div1 = document.getElementById('firstDiv');
    div1.insertAdjacentHTML('afterend', '<div id="secondDiv">Second <strong>div</strong></div>');
  </script>
</body>
</html>

See also

a
abbr
acronym
address
applet
area
article
aside
b
bdo
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
custom
dd
del
dfn
dir
div
dl
dt
em
embed
fieldSet
figcaption
figure
font
footer
form
frame
frameSet
head
header
hgroup
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
isIndex
kbd
label
legend
li
listing
map
mark
marquee
menu
nav
nextID
noBR
object
ol
optGroup
option
p
plainText
pre
q
rt
ruby
s
samp
section
select
small
span
strike
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
tt
u
ul
var
xmp
Reference
innerHTML
insertAdjacentText
outerHTML

 

 

Anzeigen:
© 2014 Microsoft