How do I achieve it?
I have a module named “tooltip” which has a “fade” function which in turn uses a global “element” variable. That variable is a reference to an element of the DOM. I want to update it from another module named “lightbox” so I could just let the “fade” function handle the fade-in effect. All my modules are declared using a closure.
var tooltip = function{
var element;
return{
fade: function(){ fade code goes here...}
};
}();
Can I just do the following to update “element” from the lightbox module?
tooltip.element = document.getElementByID('lightbox-con');
No jQuery code pls…
If with module you mean object then you can just do like this:
then you can update the element as you described:
But if
elementis only used in thefadefunction, you could also consider to just pass the element to that function:and do:
It depends on what you actually want to do.