[thelist] setAttribute in IE 5

Peter-Paul Koch gassinaumasis at hotmail.com
Sun Mar 31 07:34:00 CST 2002



>if (document.getElementById) {
>   obj = document.getElementById('div1');
>   if (obj.setAttribute) {
>     newTop = 'top:' + (obj.getAttribute('top') + 100) + 'px';
>     obj.setAttribute('style',newTop);
>   }
>}
>
>Have tried everything that seemed like it would make sense ... how do you
>use setAttribute in IE, or is it just there for the heck of it?

Do yourself a favour and keep it simple <g>. The DIV itself has no attribute
named top; using setAttribute to set styles is unreliable (I forget in which
browser).

Simply do something like

obj.style.top = parseInt(obj.style.top) + 100 + 'px';

Or see http://www.xs4all.nl/~ppk/js/index.html?getstyles.html for a script
that helps you find the current style of the object.

ppk

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com




More information about the thelist mailing list