0

This is common.js

jQuery(function ($) {

    var commonJs = {
        init: function () {
        },
        showAlert: function () {
        },

    }

});

This is add.js

jQuery(function ($) {

    var addJs = {
        init: function () {
            console.log(commonJs.showAlert);
        },
    }

});

I want to use common js function commonJs.showAlert in add.js

How can i access that?

2 Answers 2

-1

Please simply place commonJs var outside the jQuery function and try again. It will work for you.

1
  • Thank you. It worked Mar 19, 2020 at 5:02
0
var commonJs;
jQuery(function ($) {

    commonJs = {
        init: function () {
        },
        showAlert: function () {
        },

    }

});

I just had to put this variable outside jQuery(function ($) and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.