[Javascript] OOP and the DOM

girzel girzel at gmail.com
Mon Oct 22 02:18:53 CDT 2007


Excellent, thanks to all who replied. This is slowly starting to make  
more sense.

I've got one more question before I try writing this. Scott wrote:


>> I also don't know if it's possible to 'actually' connect the
>> class instances to the DOM elements: would a Category class have a
>> this.element = d.getElementsByID() attribute in it?
>
> Yes.  But the DOM itself is already indexing every node ID, so this
> isn't likely much if any optimization.  Your real efficiency
> improvements will likely be in picking out the links in advance, as
> it's unlikely the links are pre-indexed automatically.
>
> Peace,
> Scott

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?

Thanks again,
Eric




More information about the Javascript mailing list