Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling local function with Jquery

Tags:

jquery

I have a jQuery function as follows:

(function ($) {
    $.fn.autoSuggest = function (data, options) {
        function add_selected_item(data, num) {
            (function ($) {
                $.fn.autoSuggest = function (data, options) {
                    alert(data);
                }
            })(jQuery);
        }
    }
})(jQuery);

If I wanted to call the local add_selected_item() function from outside this function, how would I do it?

I've tried doing:

$.autoSuggest.add_selected_item(data, opt);

But am getting an $.autoSuggest is undefined.

Still learning the ropes with jQuery. I am not sure exactly how this can be accomplished, if at all.

Thanks!

like image 282
Bug Magnet Avatar asked Jun 04 '26 18:06

Bug Magnet


1 Answers

Try this :

$.extend({
  autoSuggest: function(){
    ...
  }
});

or

$.fn.autoSuggest = function(){
  ...
};
like image 182
CrazyMax Avatar answered Jun 07 '26 23:06

CrazyMax