possible to add methods to HTMLElements?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lopi

    #1

    possible to add methods to HTMLElements?

    Hi, I'm trying to add the method nextSibling to a HTMLElement such as
    a DIV in the body of a html document.
    Once the function nextSibling was defined
    function sibling () {
    return( document.all[this.children.l ength+1] );
    }
    I tried to add the method by the following instruction
    HTMLElement.pro totype.nextSibl ing=sibling;
    but it seems it does not work. Probably the class has to be named
    somehow else. Who knows a complete list of classes/object?

    Can anyone help? TIA
  • Martin Honnen

    #2
    Re: possible to add methods to HTMLElements?



    lopi wrote:
    [color=blue]
    > Hi, I'm trying to add the method nextSibling to a HTMLElement such as
    > a DIV in the body of a html document.
    > Once the function nextSibling was defined
    > function sibling () {
    > return( document.all[this.children.l ength+1] );
    > }
    > I tried to add the method by the following instruction
    > HTMLElement.pro totype.nextSibl ing=sibling;
    > but it seems it does not work. Probably the class has to be named
    > somehow else. Who knows a complete list of classes/object?[/color]

    It obviously depends on the browser but for a start try the DOM section
    on http://www.w3.org/, there you will find that nextSibling is a
    property defined in DOM Level 2 Core.
    As for adding method to HTMLElement, as far as I know only Mozilla based
    browsers allow that, others like IE or Opera don't do that.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    Working...