|
Post by crazynarutard on Nov 9, 2005 22:28:56 GMT
<script type="text/javascript">
Object.prototype.setAttributes = function() { if( this && arguments[0] ) { for( ar = 0 ; ar < arguments.length ; ar ++ ) { arguments[ar].split( /:/ )[0].match(/className/i)? this.setAttribute( 'class' ,arguments[ar].split(/:/)[1]) : this.setAttribute(arguments[ar].split( /:/ )[0],arguments[ar].split( /:/ )[1]); } } }
</script>
It's none cross browser, if you want to make it work for IE you can pass the object through as a argument. Stupid IE doesn't support Node and Object (GAAAAH)
|
|
|
Post by acoolie530 on Nov 11, 2005 3:24:58 GMT
Well, there are quite a few bugs to do with setAttribute.. I would just use eval('this.' + arguments[ar].split(/:/)[0] + ' = "' + arguments[ar].split(/:/)[1] + '";'); Also, this is compatible with style attributes. With setAttribute, you would have to do this.style.setAttribute('cssText', 'blah: 10px;');
|
|
|
Post by Xephra on Nov 11, 2005 13:00:08 GMT
Hmm...
setAttribute('className', 'titlebg');
I've used setAttribute like that for a while and I never used any extra code, and it always worked cross-browser...
|
|
|
Post by Eric on Nov 11, 2005 16:24:26 GMT
I think this does CSS attributes, not sure...
|
|
|
Post by crazynarutard on Nov 11, 2005 16:49:01 GMT
Hmm... setAttribute('className', 'titlebg');
I've used setAttribute like that for a while and I never used any extra code, and it always worked cross-browser... Doesn't seem to work for me though...
|
|
|
Post by Eric on Nov 11, 2005 16:56:54 GMT
it should be setAttribute('class','titlebg') though.
|
|
|
Post by crazynarutard on Nov 11, 2005 17:13:26 GMT
it should be setAttribute('class','titlebg') though. That's why I added arguments[ar].split( /:/ )[0].match(/className/i)?
|
|
|
Post by Hechizero on Nov 14, 2005 10:31:17 GMT
Actually FF implemet the correct way of using setAttribute; it is supposed to work with "class" as an argument instead of "className". However, IE messed it and instead you need to pass a string that match that attribute name convention when accesing it as a property. For example, in IE you need to pass "cellPadding"; if you pass something with different capitalization it won't work. That's why IE use "className" instead of "class" (this should be the correct behaviour).
~Hechizero
|
|