possible to add methods to HTMLElements?

L

lopi

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.length+1] );
}
I tried to add the method by the following instruction
HTMLElement.prototype.nextSibling=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
 
M

Martin Honnen

lopi said:
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.length+1] );
}
I tried to add the method by the following instruction
HTMLElement.prototype.nextSibling=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?

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.
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top