nextSibling on element retrieved from document

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>
 
T

Thomas 'PointedEars' Lahn

pr said:
Dr. Leff said:
I am having trouble with the nextSibling. [...]
Before = aarb.nextSibling();
[...]

nextSibling is a property not a method so you don't want the brackets.

See http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247

To be exact, `nextSibling' is an *attribute* of that interface, and a
non-callable property of an (ECMAScript) object implementing that interface.

In ECMAScript implementations (e.g. in contrast to Java or C++), all
methods of an object are properties of that object, but not vice-versa.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top