[Javascript] Apply padding via javascript

Steven Chipman sgchipman at gmail.com
Sat Aug 19 17:01:50 CDT 2006


>
> what would be the best out of the following 2 options?
>
>     document.all.MyBlock.style
> or
>     document.layers['MyBlock'].style
>

Neither. document.all is proprietary to Microsoft's DOM (though
supported by Opera and invisibly supported by other browsers for
compatibility), and document.layers only works in Netscape 4.x (and
possibly lower versions, my memory fails.).

You want to use the W3C equivalent:

document.getElementById("MyBlock").style.padding = "4px";

The above is supported by all modern, standards compliant browsers -
MSIE, Opera, Firefox, Mozilla, Safari, etc.

Rather than setting the padding directly, I recommend applying a class
to the object that defines your padding:

document.getElementById("MyBlock").className = "yourClass";

For more information on the W3C DOM, see my recent presentation on the
topic here:
http://slayeroffice.com/articles/DOM



steve

--
S.G. Chipman
slayeroffice.com



More information about the Javascript mailing list