Exportar (0) Imprimir
Expandir Todos
go
Expand Minimize
EN
Este conteúdo não está disponível no seu idioma mas aqui tem a versão em inglês.
6 de 8 classificaram como útil - Classificar este tópico

insertAdjacentElement method

Inserts an element at the specified location.

Syntax

object.insertAdjacentElement(where, insertedElement)

Parameters

where [in]

Type: String

A String that specifies where to insert the HTML element, using one of the following values.

beforeBegin

Inserts insertedElement immediately before the object.

afterBegin

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

beforeEnd

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

afterEnd

Inserts insertedElement immediately after the end of the object.

insertedElement [in]

Type: IHTMLElement

Object that specifies the element to be inserted adjacent to the object that invoked the insertAdjacentElement method.

Return value

Type: IHTMLElement

Returns an element object.

Standards information

There are no standards that apply here.

Remarks

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

If you try to insert an object that already exists on the page, the existing object is moved to the point that you specified in the insertAdjacentElement method; no new object is created.

Examples

This example uses the insertAdjacentElement method to add a new list item to an ol object.


<!DOCTYPE html>
<html>

<head>
  <title>insertAdjacentElement</title>
</head>

<body>
  <ol id="oList">
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
  </ol>
  <input type="button" value="Add Item" onclick="fnAdd()">
  <script>
    function fnAdd() {
      var oNewItem = document.createElement("li");
      oList.children(0).insertAdjacentElement("BeforeBegin", oNewItem);
      oNewItem.innerText = "List Item 0";
    }
  </script>
</body>

</html>

See also

a
abbr
acronym
address
applet
area
b
base
baseFont
bdo
bgSound
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
comment
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

 

 

Considera isto útil?
(1500 caracteres restantes)
Obrigado pelos seus comentários
Mostrar:
© 2014 Microsoft. Todos os direitos reservados.