Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > nextSibling on element retrieved from document

Reply
Thread Tools

nextSibling on element retrieved from document

 
 
Dr. Leff
Guest
Posts: n/a
 
      10-14-2007
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>

 
Reply With Quote
 
 
 
 
pr
Guest
Posts: n/a
 
      10-14-2007
Dr. Leff wrote:
> 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-Cor...#ID-1950641247
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-14-2007
pr wrote:
> Dr. Leff wrote:
>> 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-Cor...#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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
firstChild and nextSibling difference VK Javascript 2 04-23-2006 11:33 AM
Getting next tag in list, nextSibling gives unexpected results Marc Javascript 6 04-21-2006 10:10 AM
trouble using .nextSibling 2obvious Javascript 5 07-14-2005 08:26 PM
set begin() retrieved the minimum element? pmatos C++ 18 06-26-2005 07:51 AM
nextSibling doesn't work BillKi Javascript 12 05-28-2005 10:50 AM



Advertisments