<html>
<head>
<title>Gecko DOM insertBefore test</title>
</head>
<body>
<div>
<span id="childSpan">foo bar</span>
</div>
<script type="text/javascript">
// create an empty element node
// without an ID, any attributes, or any content
var sp1 = document.createElement("span");
// give it an id attribute called 'newSpan'
sp1.setAttribute("id", "newSpan");
// create some content for the newly created element.
var sp1_content = document.createTextNode("This is a new span element. ");
// apply that content to the new element
sp1.appendChild(sp1_content);
var sp2 = document.getElementById("childSpan");
var parentDiv = sp2.parentNode;
// insert the new element into the DOM before sp2
parentDiv.insertBefore(sp1, sp2);
</script>
</body>
</html>