468,135 Members | 1,467 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,135 developers. It's quick & easy.

How to set margin-left in IE w/Javascript

I basically have this....

<div id="page">
<div id="leftPane">
picture previews
</div>
<div id="Picture">
A picture here
</div>
</div>

I'm trying to do this in javascript

function setMargin()
{
document.getElementById("Picture").style.margin-left = "200px";
}

Except, that doesn't set the margin properly in IE. In FF & opera it
works fine.

Any ideas??? Thanks!

Aug 24 '06 #1
4 54155
guywmustang wrote:
[...]
I'm trying to do this in javascript

function setMargin()
{
document.getElementById("Picture").style.margin-left = "200px";

document.getElementById("Picture").style.marginLef t = "200px";

<URL:
http://www.w3.org/TR/DOM-Level-2-Sty...ies-marginLeft
>
}

Except, that doesn't set the margin properly in IE. In FF & opera it
works fine.
Not for me - I get an error "invalid assignment left-hand side" as
expected.

--
Rob

Aug 24 '06 #2
Sorry.... my code actually says:

function setMargin()
{
document.getElementById("Picture").style.marginLef t = "200px";
}

And it still doesn't set properly for IE....

Aug 24 '06 #3
guywmustang wrote:
Sorry.... my code actually says:

function setMargin()
{
document.getElementById("Picture").style.marginLef t = "200px";
}

And it still doesn't set properly for IE....
Then there is something else in the 'real' page that is stopping it
from working in IE. I suggest posting to:

news:comp.infosystems.www.authoring.stylesheets
A link to the relevant page, or an example, will really help. As a
test, the following works in IE and Firefox at least:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>Margin play</title>
<div id="page">
<div id="leftPane">
picture previews
</div>
<div id="Picture">
A picture here
</div>
</div>
<p><input type="button" value="Indent div" onclick="
document.getElementById('Picture').style.marginLef t = '200px';
"></p>
--
Rob

Aug 24 '06 #4
guywmustang wrote:
>
[snip] Except, that doesn't set the margin properly in IE. In FF & opera it
works fine.

Any ideas??? Thanks!
Wouldn't this be far better done with CSS anyway? Or is CSS still not
reliable in IE?
Aug 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brian | last post: by
19 posts views Thread by Thomas Mlynarczyk | last post: by
1 post views Thread by Marek Mänd | last post: by
13 posts views Thread by Cool Guy | last post: by
3 posts views Thread by xen | last post: by
2 posts views Thread by Steve Richter | last post: by
reply views Thread by GTalbot | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.