Proper Variable Use

Proper Variable Use

What I'm trying to accomplish:

First, I want to store the default height(current set height) of various ids for later use. I then want to set the height value of those ids when a button(s) is clicked. Since this will happen many times, I want to save the value of all these heights as a variable, and then call the variable within a click function.

This is what I have so far:

var selectedDivs = $('#div1, #div2, #div3, #div4, #div5, #div6, #div7);
                var divDefaultHeight = selectedDivs.height(function(index, height) {
                    return (height);
                });
                var divSetHeight = selectedDivs.height(function(index, height) {
                    return (height - 312 + 4);
                });
I have little idea of how to call the variable when I need it. My instinct is to try and run the variable like a function, which doesn't sound right. I've tried to wrap it in a function, but it doesn't seem to work. The little success I've had is by calling a variable followed by a function (e.g. variablename.function();). However, shouldn't I store the function as part of the variable, since it will be executed many times? I'm probably going about this all wrong, which is why I ask.

Additionally- Does a function within a variable still execute immediately? For some reason I was under the impression that it would only execute when the variable was called.

Any help would be appreciated.


-Please excuse any present programming language ignorance belonging to me. I desire to learn the most I can, unfortunately the process must start from crude origins.