Export (0) Print
Expand All
go
Expand Minimize

replaceNode method

Replaces the object with another element.

Syntax

object.replaceNode(replacement)

Parameters

replacement [in]

Type: IHTMLDOMNode

An Object that specifies the new element to replace the object.

Return value

Type: IHTMLDOMNode

Returns a reference to the object that is replaced.

Standards information

There are no standards that apply here.

Remarks

When a node is replaced, all values that are associated with the replaced object are removed. For example, if a b object is replaced with an i object, any attributes and text between the opening and closing tags are also replaced. To preserve these values, copy them to the new element before the original object is replaced.

This method is accessible at run time. If elements are removed at run time before the closing tag is parsed, areas of the document might not render.

Examples

This example uses the replaceNode method to replace an unordered list with an ordered list.


<!DOCTYPE html>

<html>
<head>
  <title>replaceNode</title>
</head>
<body>
  <ul id="oList">
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
    <li>List Item 4</li>
  </ul>
  <input type="button" value="Replace List" onclick="fnReplace()">
  <script>
    function fnReplace() {
      var oList = document.getElementById('oList');
      var sPreserve = oList.innerHTML;
      var oNewNode = document.createElement("ol");

      oList.replaceNode(oNewNode);
      oNewNode.innerHTML = sPreserve;
    }
  </script>
</body>
</html>

See also

a
abbr
acronym
address
applet
area
article
aside
attribute
b
base
baseFont
bdo
bgSound
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
comment
dd
del
dfn
dir
div
dl
documentType
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
kbd
label
legend
li
link
listing
map
mark
marquee
menu
nav
nextID
object
ol
option
p
plainText
pre
ProcessingInstruction
q
s
samp
script
section
select
small
span
strike
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
tt
u
ul
var
xmp
Reference
replaceChild
Conceptual
About the W3C Document Object Model

 

 

Show:
© 2014 Microsoft