JavaScript Reference/Javascript Methods/insertBefore
"insertBefore()" Example
<html>
<body>
<script language="JavaScript">
function function1() {
var myElement = document.createElement("<div style="width:300; height:200;background-color:blue;"></div>");
document.all.myDiv.insertBefore(myElement);
}
</script>
<button id="myButton" onclick="function1();">Insert element</button>
<div id="myDiv" style="width:300; height:200;"></div>
</body>
</html>
"insertBefore()" is applied to
+----------------+--------------------------------------------------------------+
| Applied_To |<a> <acronym> |
| |<address> <applet> |
| |<area> attribute |
| |<b> <base> |
| |<basefont> <bdo> |
| |<big> <blockquote> |
| |<body> <br> |
| |<button> <caption> |
| |<center> <cite> |
| |<code> <col> |
| |<colgroup> <comment> |
| |<dd> <del> |
| |<dfn> <dir> |
| |<div> <dl> |
| |<dt> <em> |
| |<fieldset> <font> |
| |<form> <frame> |
| |<frameset> <head> |
| |<hn> <hr> |
| |<html> <i> |
| |<iframe> <img> |
| |<input type="button"> <input type="checkbox"> |
| |<input type="file"> <input type="image"> |
| |<input type="password"> <input type="radio"> |
| |<input type="reset"> <input type="submit"> |
| |<input type="text"> <ins> |
| |<isindex> <kbd> |
| |<label> <legend> |
| |<li> <link> |
| |<listing> <map> |
| |<marquee> <menu> |
| |<meta> <noframes> |
| |<noscript> <object> |
| |<ol> <optgroup> |
| |<option> <p> |
| |<param> <plaintext> |
| |<pre> <q> |
| |<s> <samp> |
| |<script> <select> |
| |<small> <span> |
| |<strike> <strong> |
| |<style> <sub> |
| |<sup> <table> |
| |<tbody> <td> |
| |<textarea> <tfoot> |
| |<th> <thead> |
| |<title> <tr> |
| |<tt> <u> |
| |<ul> <var> |
| |<xmp> |
+----------------+--------------------------------------------------------------+
"insertBefore()" Syntax, Parameters and Note
Note:
Inserts an element either at the end of the document or after the specified element.
Syntax:
document.getElementById("elementID").insertBefore(param1, param2)
document.all.elementID.insertBefore(param1, param2) // IE only
Parameters:
param1 Required; the new element.
param2 Optional; the element after which to insert the new element.
If omitted, insert at the end.