Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  128] [ 1]  / answers: 1 / hits: 16153  / 11 Years ago, tue, september 24, 2013, 12:00:00

I am trying to call the nested function is not working

Here is what I tried jsfiddle



Script:



(function( $ ){
$.fn.investPage = function() {
function setupFCConfig(){
$('.nestedFunction').click(function(){
alert('setupFCConfig func()');
});
}
$(.edit).on('click', function(){
alert('edit click func()');
});
$(.cancel).on('click', function(){
alert('cancel click func()');
});
$(.checkout).click(function(){
alert('checkout click func()');
});
};
})( jQuery );

$.fn.investPage();
$.fn.investPage.setupFCConfig();

More From » jquery

 Answers
27

setupFCConfig() is NOT a property of the $.fn.investPage object so it can't be called like this:



 $.fn.investPage.setupFCConfig();


It is a local function that is not available outside the scope in which it is declared. If you want it available from an outside scope, then you need to assign it to be a property of some object that is available in that outside scope.



For example, you could change the definition of that function to be like this:



(function( $ ){
$.fn.investPage = function() {
$(.edit).on('click', function(){
alert('edit click func()');
});
$(.cancel).on('click', function(){
alert('cancel click func()');
});
$(.checkout).click(function(){
alert('checkout click func()');
});

};
$.fn.investPage.setupFCConfig = function (){
$('.nestedFunction').click(function(){
alert('setupFCConfig func()');
});
}

})( jQuery );

$.fn.investPage();
$.fn.investPage.setupFCConfig();


FYI, you also need to fix the misspelling of .click.


[#75479] Monday, September 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tylerdamiena

Total Points: 139
Total Questions: 90
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
tylerdamiena questions
;