tags:

views:

118

answers:

1

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.

+1  A: 

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.

TheVillageIdiot
and ensure you include it after the jquery core...
redsquare
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.js2. jquery.common.js (has the call to googleMap function in it--------3. google map API4. jquery.googlemap.jsIt may be why I am now getting this on every page in firebug:$("#location div").r...ap is not a function
Daniel
Daniel
Yes you will have to include the **googleMap.js** file before your **jquery.common.js** file.
TheVillageIdiot
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.
Daniel