Skip to main content

Windows Dev Center

swapNode method

Exchanges the location of two objects in the document hierarchy.

Syntax

object.swapNode(otherNode)

Parameters

otherNode [in]

Type: IHTMLDOMNode

Object that specifies the existing element.

Return value

Type: IHTMLDOMNode

Returns a reference to the object that invoked the method.

Standards information

There are no standards that apply here.

Remarks

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 swapNode method to exchange the location of two objects.


<!DOCTYPE html>

<html>
<head>
  <title>swapNode</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="Swap List" onclick="fnSwap()">
  <script>
    function fnSwap() {
      var oList = document.getElementById('oList');

      oList.children[0].swapNode(oList.children[1]);
    }
  </script>
</body>
</html>

See also

a
abbr
address
area
article
aside
attribute
b
base
bdo
bgSound
blockQuote
body
br
button
caption
cite
code
col
colGroup
comment
dd
del
dfn
div
dl
documentType
dt
em
embed
fieldSet
figcaption
figure
footer
form
frame
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
map
mark
menu
nav
object
ol
option
p
pre
ProcessingInstruction
q
s
samp
script
section
select
small
span
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
u
ul
var
Reference
cloneNode
removeNode
replaceNode
Conceptual
About the W3C Document Object Model