replaceNode method (Internet Explorer)

Switch View :
ScriptFree
replaceNode method

[This documentation is preliminary and is subject to change.]

Replaces the object with another element.

Syntax

object.replaceNode(replacement)

Standards information

There are no standards that apply here.

Parameters

replacement [in]

Type: IHTMLDOMNode

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

Return value

Type: ObjectReturns a reference to the object that is replaced.

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.


<SCRIPT>
function fnReplace(){
   var sPreserve = oList.innerHTML;
   var oNewNode = document.createElement("OL");
   oList.replaceNode(oNewNode);
   oNewNode.innerHTML = sPreserve;
}
</SCRIPT>
<UL ID = oList>
<LI>List Item 1
<LI>List Item 2
<LI>List Item 3
<LI>List Item 4
</UL>
<INPUT TYPE = button VALUE = "Replace List" onclick = "fnReplace()">

See also

Attr Constructor
a
abbr
acronym
address
applet
area
attribute
article
aside
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=file
input type=hidden
input type=image
input type=password
input type=radio
input type=reset
input type=submit
input type=text
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
Element Constructor
HTMLDocument Constructor
Text Constructor
Reference
replaceChild
Conceptual
About the W3C Document Object Model

 

 

Build date: 2/14/2012

Community Content

Mr. Raymond Kenneth Petry
clarification, correction

1. (CLAR) oReplace is oReplaced a copy of the original elementobject and its innerHTML.

2. (CORR) The original element object that is replaced still exists with all its innerHTML, as an object, no longer an element in HEADER or BODY. It still exists by its original id.

3. (CORR) The original object.innerHTML needs not be preserved, but transferred....

4. (CLAR) When the replaceNode() executes, the oNewNode object replaces the original element object in HEADER or BODY ... But it has no class nor id yet...

e.g. A simpler clearer example might be--

<SCRIPT>
function fnReplace()
{
var oNewNode = document.createElement("OL");
oNewNode.innerHTML = oList.replaceNode(oNewNode).innerHTML;
}
</SCRIPT>

List Item 1
List Item 2
List Item 3
List Item 4
<INPUT TYPE = button VALUE = "Replace List" onclick = "fnReplace()">

5. Also, Clarification: Some prior content was deflected by 1. the clarification trouble above, 2. similar trouble with idElement.outerHTML = '<eHTML></eHTML>' does-not update outerHTML within the event handler; (and 3. This forum editer is messed-up, dropping single-space between "<u>xxx</u> <em>xxx</em>", and, Process Errors!).