Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Reducing Code

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reducing Code

    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) {
    Div1px10();
    }

    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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how about


    Code:
    function objectTop(objId,pos) {
    
        document.getElementById(objId).style.top = pos + "px";
    
        }

    which you can call like this

    Code:
    objectTop("div1",10);

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome Brothercake, thank you.

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

    objectTop("div",a+b);

    objectTop("div",ReturnToBottom());


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •