View Full Version : Reducing Code

Graeme Hackston
07-30-2002, 05:07 PM
I've found that I can reduce code by creating a function and calling it when it's required. Like this:

function Div1px10() {
document.getElementById('div1').style.top = "10px";

Then I call it like this

if (SomeVar) {

Is there a way to do something like this?

function Div1Top() {
document.getElementById('div1').style.top ;

And then call it in another function like this?

if (SomeVar) {
Div1Top() = "20px"

I hope this makes sense, thanks for your help.

07-30-2002, 05:20 PM
how about

function objectTop(objId,pos) {

document.getElementById(objId).style.top = pos + "px";


which you can call like this


Graeme Hackston
07-30-2002, 10:55 PM
Awesome Brothercake, thank you.

Are these syntaxes correct? They work in IE6 and Mozilla 1.0 but I don't think that means much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum