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!