nextSibling on element retrieved from document

Discussion in 'Javascript' started by Dr. Leff, Oct 14, 2007.

  1. Dr. Leff

    Dr. Leff Guest

    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>
    Dr. Leff, Oct 14, 2007
    #1
    1. Advertising

  2. Dr. Leff

    pr Guest

    pr, Oct 14, 2007
    #2
    1. Advertising

  3. 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-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
    Thomas 'PointedEars' Lahn, Oct 15, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    18
    Views:
    522
    Steven T. Hatton
    Jun 26, 2005
  2. BillKi

    nextSibling doesn't work

    BillKi, May 23, 2005, in forum: Javascript
    Replies:
    12
    Views:
    630
    Thomas 'PointedEars' Lahn
    May 28, 2005
  3. 2obvious

    trouble using .nextSibling

    2obvious, Jul 14, 2005, in forum: Javascript
    Replies:
    5
    Views:
    158
    2obvious
    Jul 14, 2005
  4. Marc
    Replies:
    6
    Views:
    123
    Michael Winter
    Apr 21, 2006
  5. VK
    Replies:
    2
    Views:
    103
Loading...

Share This Page