[Javascript] Wrestling with DOM access (artificial attributes, IE vs Firefox vs Safari)

Triche Osborne wdlists at triche-osborne.com
Sat Aug 6 10:41:30 CDT 2005


Charles Albrecht wrote:
> In my case, the element I'm looking at is something like:
> 
> <tr id="row512" level="2" hidecount="0" expanded="true">  [1]
> 
> . . . Actually, I'd probably prefer to get them
> out of the tag attributes so the page will come closer to validating
> against its doctype.
> 
> I was trying to think of other ways of doing this. Perhaps trying to
> get the values out of the DOM into an object or series of objects (one
> for each of mytable.getElementsByTagName("tr")). But of course, it all
> needs to tie back to the DOM.

I often initialize new instance properties (onload) for form validation. 
I know this works in Moz/FF and IE, though I've not tested in others. 
You could to the same with your TRs, providing it works in the browsers 
you're concerned about. Something like . . .

function instantiate()
{
	var rows = document.getElementsByTagName("tr");
	for(var i=0; i < rows.length; i++)
	{
		rows[i].newProperty = "initialPropertyValue";
	}
}

This attaches the property to the rows without impinging on your XHTML. 
Your remaining functions can alter the value of the property from there.

Triche




More information about the Javascript mailing list