1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
<BODY>
<STYLE>
DIV { border: 2px solid khaki; }
</STYLE>
<SCRIPT>
var nextID = 1;
function getIndex()
{
var it = document.getElementById("getid");
var index = it.value;
if (index == "") index = 0;
return index;
}
function makeInline()
{
var image = document.createElement("IMG");
image.setAttribute("SRC", "bluedot.gif");
image.setAttribute("WIDTH", "100");
image.setAttribute("HEIGHT", "40");
image.setAttribute("BORDER", "2");
image.setAttribute("ID", "obj" + nextID);
nextID++;
return image;
}
function makeBlock()
{
var block = document.createElement("DIV");
var text = document.createTextNode("Block Text");
block.appendChild(text);
block.setAttribute("ID", "obj" + nextID);
nextID++;
return block;
}
function appendInline()
{
var i = makeInline();
var it = document.getElementById("it");
it.appendChild(i);
}
function insertInline()
{
var i = makeInline();
var it = document.getElementById("it");
var kids = it.childNodes;
var index = getIndex();
if ((index < 0) || (index > kids.length)) index = 0;
var before = kids[index];
it.insertBefore(i, before);
}
function appendBlock()
{
var b = makeBlock();
var it = document.getElementById("it");
it.appendChild(b);
}
function insertBlock()
{
var b = makeBlock();
var it = document.getElementById("it");
var kids = it.childNodes;
var index = getIndex();
if ((index < 0) || (index > kids.length)) index = 0;
var before = kids[index];
it.insertBefore(b, before);
}
</SCRIPT>
<FORM>
<INPUT TYPE=button ONCLICK="appendInline();" value="Append Inline">
<INPUT TYPE=button ONCLICK="insertInline();" value="Insert Inline">
<INPUT TYPE=button ONCLICK="appendBlock();" value="Append Block">
<INPUT TYPE=button ONCLICK="insertBlock();" value="Insert Block"><BR>
<INPUT TYPE=text value="" ID="getid">
</FORM>
<HR>
<B ID=it></B>
</BODY>
|