0

I inserted some jquery code which is designed for an feature of one page into my common js file. Now all pages are throwing an error and I think it is because I don't understand the difference between a jQuery function and a normal one. The jQuery one starts off like this:

$.fn.googleMap = function(address, options) {

and is called from within the $(document).ready(function(){ like this:

$("#location div").removeClass().googleMap(""+location1+"");

I tried (just in case) to do: function googleMap(address, options) { ...but then I am not sure if that 1. works and 2. how to trigger it from within "$(document).ready" part.

asked Aug 24, 2009 at 7:53

1 Answer 1

1

extract the jquery function into a separate file and include it in the pages where you are calling the method as with other jquery plugins.

answered Aug 24, 2009 at 7:57
Sign up to request clarification or add additional context in comments.

4 Comments

I've done what you've said and it seems to be working but in theory it shouldn't have because of the load order I have had to put it in. You see, the site has global includes which makes it hard - I will indicate the global files with the dashed line: -------- 1. jquery-1.3.1.min.js 2. jquery.common.js (has the call to googleMap function in it -------- 3. google map API 4. jquery.googlemap.js It may be why I am now getting this on every page in firebug: $("#location div").r...ap is not a function
Is it a matter of pulling 3 & 4 into #2? How would I suck in javascript from a javascript file?
Yes you will have to include the googleMap.js file before your jquery.common.js file.
Thanks for your help. In the end I made another $(document).ready function in the jquery.googleMap.js file and thus enabled everything to load in the correct order. I forgot you could have 2 document ready functions, your last message prompted me.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.