Re: how to display the margin of a <p> element
On Mar 17, 4:18 pm, Jeremy <jer...@pinacol.com> wrote:
> Seehttp://www.quirksmode.org/dom/getstyles.htmlfor a useful
> cross-browserish method of getting the current style of an element.
thanks for the tip.
so
function getStyle(el,styleProp)
{
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y =
document.defaultView.getComputedStyle(x,null).getP ropertyValue(styleProp);
return y;
}
alert(getStyle("ha", "marginTop"))
will show "auto" in IE and an empty string in Firefox. If I add a
style for <p> as margin: 10px, then IE will show 10px and Firefox will
not show anything.
|