Afficher un message
Vieux 18/03/2008, 00h39   #4
Summercool
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to display the margin of a <p> element

On Mar 17, 4:36 pm, Summercool <Summercooln...@gmail.com> wrote:

> 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.


and even if in Firefox, the getStyle is added these 2 lines:

console.log(x.currentStyle)

console.log(document.defaultView.getComputedStyle( x,null).getPropertyValue(styleProp))

for it to show in FireBug, nothing will be displayed.



  Réponse avec citation
 
Page generated in 0,04374 seconds with 9 queries