1

I am facing one problem I am trying to call document.ready() function inside another JavaScript function but when I am calling it, it says "function is not defined

Here is my code : this is first function that is document.ready() function

$(document).ready(function ExpandMessageBox() {// this is my document.ready function. I have given the name of it as "ExpandMessageBox"}

this is another regular JavaScript function in which I am trying to call above function

function ShowMessageBox() {
    ExpandMessageBox();}

But this is giving me an error as : "Uncaught ReferenceError: ExpandMessageBox is not defined"

Where I am doing wrong... Please Help

Tons of thanks in advance

1
  • u will have to define ExpandMessageBox outside the function scope of the ready() function for it to be accessible by the ther function Commented Jul 28, 2017 at 11:28

1 Answer 1

2

You need to define ExpandMessageBox function in the common scope. Something like this:

function ExpandMessageBox() {
  //your staff
}
function ShowMessageBox() {
  ExpandMessageBox();
}
$(document).ready(ExpandMessageBox);
Sign up to request clarification or add additional context in comments.

7 Comments

I am calling $('div.Messageheader').click(function()), for that I have to put this code inside $(document).ready() function.... If I removed the $(document).ready() then, the click event of div not firing
So what a problem to put $('div.Messageheader').click(function()) instead of my code comment //your staff to achieve what you want? Or what am I missed?
yes...initially I did this only... but the click even does not fire.. So I searched for that...and I found that.. this code should be inside of $(document).ready(); function.
if you need just call click event on that element, you can $('div.Messageheader').trigger('click')
Can you please explain me how to use this??? I Mean how "$('div.Messageheader').trigger('click')" will call the function??? should I write the "onclick" event for that div???
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.