Top Menu

I was editing some code a few days ago, and I added another function within the scope of $(function{}); and I called it within my JavaScript code, and it kept giving me reference errors. After a few minutes I got frustrated and tried to make a simple HTML code call the JavaScript function and nothing. Same error!

I decided to get the new function out of the $(function {} ); area and place it right above it, and wouldn’t you know. It worked.

Does Not Work

When linkClick value is added to the HTML and clicked, I get a reference error.


When I move myFunction out of the $(function() {}); scope it works.

I kept searching for a reason why this happens. Is it a browser thing? Scope thing? Ajax thing? I couldn’t find an exact answer. What do you think?

About The Author

I write about my life! I would appreciate it if you comment and tell me how life is treating you? :)


  1. Nice Work Mona Please keep going and I appreciate if you let me know latest tutorial via email.

  2. Hi Yaser,

    I have a long JavaScript tutorial that I will post in the upcoming days.

    Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">