D
Dr. Leff
I am having trouble with the nextSibling. I retrieve the position of
an
element (paragraph) in a form. I try to do a next~ibling so I can
later
insert something after the element. It does not let me do this.
I tried this both in Internet Explorer and using Mozilla. The
Mozilla tells me aarb.netSibling is not found.
When I click on the G button,
the alert tells me that the id retrieved is "g1" so it appears
the document by id is finding the paragraph containing the button
selected.
I should be able to get its next sibling. (which as you see I can
then
do an insertBefore to add an element after the paragraph containing
the
radio button just clicked.)
<HTML>
<HEAD></HEAD>
<BODY>
<SCRIPT Language="JavaScript">
document.write("GG");
function m(rbn) {
alert ("rbn is |"+rbn+"|");
var aarb = document.getElementById(rbn);
alert ("did I get it |"+aarb.id);
Before = aarb.nextSibling();
alert (" before "+Before);
var P = document.createElement("P");
var R = document.createElement("BUTTON");
R.setAttribute("TYPE","radio");
R.setAttribute("name","ga1");
R.setAttribute("value","ga1");
var TN = document.createTextNode("ga");
P.appendChild(R);
document.body.insertBefore(P,Before);
}
</SCRIPT>
<FORM name="F">
<P id="g1">
<INPUT TYPE="radio" id="g1" name="g" value="g" onClick="m('g1')">G</
INPUT>
</P>
<P id="g2">
<INPUT TYPE="radio" id="h1" name="g" value="h" onClick="m('g2')">H</
INPUT>
</P>
</FORM>
an
element (paragraph) in a form. I try to do a next~ibling so I can
later
insert something after the element. It does not let me do this.
I tried this both in Internet Explorer and using Mozilla. The
Mozilla tells me aarb.netSibling is not found.
When I click on the G button,
the alert tells me that the id retrieved is "g1" so it appears
the document by id is finding the paragraph containing the button
selected.
I should be able to get its next sibling. (which as you see I can
then
do an insertBefore to add an element after the paragraph containing
the
radio button just clicked.)
<HTML>
<HEAD></HEAD>
<BODY>
<SCRIPT Language="JavaScript">
document.write("GG");
function m(rbn) {
alert ("rbn is |"+rbn+"|");
var aarb = document.getElementById(rbn);
alert ("did I get it |"+aarb.id);
Before = aarb.nextSibling();
alert (" before "+Before);
var P = document.createElement("P");
var R = document.createElement("BUTTON");
R.setAttribute("TYPE","radio");
R.setAttribute("name","ga1");
R.setAttribute("value","ga1");
var TN = document.createTextNode("ga");
P.appendChild(R);
document.body.insertBefore(P,Before);
}
</SCRIPT>
<FORM name="F">
<P id="g1">
<INPUT TYPE="radio" id="g1" name="g" value="g" onClick="m('g1')">G</
INPUT>
</P>
<P id="g2">
<INPUT TYPE="radio" id="h1" name="g" value="h" onClick="m('g2')">H</
INPUT>
</P>
</FORM>