View Full Version : Inserting a node between two existing nodes

01-19-2005, 10:20 PM
If I have:

<label>form control</label><input id="text0" />
<label>form control</label><input id="text1" />
<label>form control</label><input id="text2" />

Is there a way to insert a node directly after text0 or text1?

01-19-2005, 10:39 PM
Since the text fields are form elements, I think the most direct way to do it would just be to specify a span after the text box and append your string to it.

Something like:

<script type="text/javascript">

function addNode(pstr,i)
var str=document.createTextNode(pstr);
var fid="span"+i;

<body onload="addNode('I like hot dogs!',0)">
<label>form control</label><input id="text0" /><span id="span0"></span>
<label>form control</label><input id="text1" /><span id="span1"></span>
<label>form control</label><input id="text2" /><span id="span2"></span>


01-19-2005, 11:55 PM
Well, I think I have the solution for you here: Node (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247).prototype.insertBefore (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-952280727)(newChild,refChild)

01-20-2005, 12:19 AM
liorean, you are a gentleman and a scholar.

It works great.

01-20-2005, 12:49 AM
Ahh, I see Liorean. I'm just now trying to break my innerHTML habit so all these nodes and children are still kinda new to me. Sometimes answering a question you might not be totally sure about is the best way to learn something new, actually quite often. ;)


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum