[Javascript] OOP and the DOM
Scott Reynen
scott at randomchaos.com
Mon Oct 22 10:52:27 CDT 2007
On Oct 22, 2007, at 1:18 AM, girzel wrote:
> This seems to imply that an instance attribute specifically calling
> d.getElementByID() is unnecessary. In that case, how do I actually
> link the new class instances to the DOM node? This is my first
> instinct:
>
> var toggles = document.getElementById
> ("toggleBox").getElementsByTagName("a");
> for (var i = toggles.length - 1; i >= 0; i--){
> toggles[i] = new ToggleClass();}
>
> Is that all it takes to link the two?
I don't believe you can change the class of a DOM node quite like
that. I know you can make the DOM node an attribute of another
class. And I believe you can also use something like node.prototype
to add your own methods and attributes to the DOM node object
definition, but that's beyond anything I've done in JavaScript so
someone else will need to explain how prototypes work.
Peace,
Scott
More information about the Javascript
mailing list