M
Martin Rinehart
Does anyone have a robust, cross-browser attribute setting function?
I'm creating stuff with code like this:
this.table = document.createElement( 'table' );
setAttributes( this.table,
{ align:'center',
bgcolor:'#4060ff', border:1,
height:'50%', width:'50%' }
);
setAttributes( this.table.style,
{ position:'absolute',
top22*zz_top + 75) + 'px',
left22*zz_top + 175) + 'px',
zIndex: zz_top }
);
For the handful of things I've tried, Opera on KDE, this is
setAttributes():
function setAttributes( obj, attrs ) {
for ( attr in attrs ) {
// alert( obj.toString() + '.' + attr + ' = ' + attrs[attr] );
if ( obj.toString() === '[object CSSStyleDeclaration]' ) {
obj[attr] = attrs[attr];
} else {
obj.setAttribute( attr, attrs[attr] );
}
} // end of for/in loop
} // end of setAttributes()
Not pretty. I suspect it will get uglier when I try some Windows
browsers.
I'm creating stuff with code like this:
this.table = document.createElement( 'table' );
setAttributes( this.table,
{ align:'center',
bgcolor:'#4060ff', border:1,
height:'50%', width:'50%' }
);
setAttributes( this.table.style,
{ position:'absolute',
top22*zz_top + 75) + 'px',
left22*zz_top + 175) + 'px',
zIndex: zz_top }
);
For the handful of things I've tried, Opera on KDE, this is
setAttributes():
function setAttributes( obj, attrs ) {
for ( attr in attrs ) {
// alert( obj.toString() + '.' + attr + ' = ' + attrs[attr] );
if ( obj.toString() === '[object CSSStyleDeclaration]' ) {
obj[attr] = attrs[attr];
} else {
obj.setAttribute( attr, attrs[attr] );
}
} // end of for/in loop
} // end of setAttributes()
Not pretty. I suspect it will get uglier when I try some Windows
browsers.