Bharathi
Bharathi

Reputation: 1328

Call jquery method from one js to another .js document

I need to call the jquery function from one .js file to another .js file. please see my code sample here. I want call a slide() method from ChartCallback.js file.

ChartWebControl.js

var Accordian = (function () {
        "use strict";
        var Accordian = {
            slide: function () {
                   debugger;
               alert("event trigger");
            }
        };
        return Accordian;
    }());

ChartCallBack.js

this.FocusChart = ChartCallBack.FocusChart;

ChartCallBack.FocusChart = function () {


        console.log(window);
        console.log(Accordian);
        Accordian.slide(); //while call this "slide" is undefined exception thrown
}

I checked "Accordian" it was initialize with slide() method before load the ChartCallback.js.

What i did wrongly here. anyone could solve my problem.

Upvotes: 2

Views: 173

Answers (1)

Ole Borgersen
Ole Borgersen

Reputation: 1104

As long as you include both files in one html document, this should work fine. Just be aware that the order of inclusion will matter here.

<script type="text/javascript" src="ChartWebControl.js"></script>
<script type="text/javascript" src="ChartCallBack.js"></script>

In essence this will load both scripts into the same page.

If you meant to communicate with two separate html files, this is not possible without some kind of server communication.

Upvotes: 2

Related Questions