Setting Body CSS with Javascript - please show me how

J

jenngra

Hi & Good evening - can someone please show me how to do this:

<body id=page_one style=margin:100>

PAGE CONTENT

</body>




<script> ..... I want to reset the <body> margin from 100 to 50 ....

How can this be done?

Best regards, Jennifer
 
N

Nik Coughlin

Hi & Good evening - can someone please show me how to do this:

<body id=page_one style=margin:100>
</body>
<script> ..... I want to reset the <body> margin from 100 to 50 ....

document.getElementById( "page_one" ).style.margin = "50px";
 
J

jenngra

Nik said:
document.getElementById( "page_one" ).style.margin = "50px";

May I ask one more question? In a scenerio like this:

<body id=page_one style=margin:100><object id=object_one
name=object_one data="test.htm" width="500"
height="500"></object></body>

How do I set the body margin from test.htm to 50? I thought your step
would work, but I am unsure how to call this. Thank you so much, Jenn
 
N

Nik Coughlin

May I ask one more question? In a scenerio like this:

<body id=page_one style=margin:100><object id=object_one
name=object_one data="test.htm" width="500"
height="500"></object></body>

How do I set the body margin from test.htm to 50? I thought your step
would work, but I am unsure how to call this. Thank you so much, Jenn

I don't know because I would never do it that way. Using the object element
to include one file in another doesn't work very well across browsers. Read
this for better ways to do the same thing, which should make your little
problem go away:
http://allmyfaqs.net/faq.pl?Include_one_file_in_another

Also there is a bit on that page about the issues with using object.
 
N

Neredbojias

To further the education of mankind, (e-mail address removed) vouchsafed:
Hi & Good evening - can someone please show me how to do this:

<body id=page_one style=margin:100>

PAGE CONTENT

</body>




<script> ..... I want to reset the <body> margin from 100 to 50 ....

How can this be done?


You don't need to id the body element (-and probably shouldn't):

document.body.style.margin="50px";

Also, with css styles, units must be included:

<body style="margin:100px;">
 
T

Toby Inkster

jenngra said:
<body id=page_one style=margin:100>

In CSS you *must* specify units (except for '0', because 0px is the same as
0mm which is the same as 0%). That is, use '100px', not just '100'.

(The only property where units are optional is 'line-height'.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top