elepil
asked on
Basic question about jQuery
I'm still new to jQuery and still learning. Ever since I started using it, I've been putting all my JavaScript code inside:
But now I'm facing a problem where I have an <a> element with href="javascript:insideJQu ery()", and I'm getting the error message -- "Uncaught ReferenceError: insideJQuery() is not defined". This is expected because the function is inside another function, and therefore is out of scope.
But I can't really move the insideJQuery() function out of the JQuery's function because that function calls other functions within that scope that use a lot of jQuery; that's why it's there in the first place.
How can I access an inner nested function from the outside? The jQuery function isn't exactly a function I can call and have it return a reference to the inner nested function. What should I do?
Thanks.
$(function() {
function insideJQuery() {
// This function calls stuff within this jQuery function, so it has to be here.
}
}
But now I'm facing a problem where I have an <a> element with href="javascript:insideJQu
But I can't really move the insideJQuery() function out of the JQuery's function because that function calls other functions within that scope that use a lot of jQuery; that's why it's there in the first place.
How can I access an inner nested function from the outside? The jQuery function isn't exactly a function I can call and have it return a reference to the inner nested function. What should I do?
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome.
ASKER
While JulianH provided an excellent workaround for my problem, Alexandre attacked my problem from the root. I come from a classic OOP background with both Java and ActionScript, so I am still in the process of acclimating to the nuances and idiosyncrasies of the PHP and JavaScript world. I am already a heavy proponent and believer of constructor functions, which is what you demonstrated. Your response addressed directly the aspects of JavaScript that I was uncertain of, and I greatly appreciate it!
I thank you both for your high-quality solutions!