Why Doesn OpenLayers Work With jQuery?
jQuery and OpenLayers both depend on the “$” function. However, both libraries use this *only* as a shortcut, and have no problem with using a different nomenclature instead: In OpenLayers, “$” is “OpenLayers.Util.getElement”, and in jQuery, it’s just “jQuery”. It is not clear why the jQuery $ and the OpenLayers $ conflict — OpenLayers explicitly tries not to redefine $ if it is already defined — but it is also possible to redefine $: the jQuery library provides information on Using jQuery With Other Libraries which should prove helpful in this regard. Note: This issue is fixed by default in release 2.8 and later. For more discussion, see #1391. Potential fixes, if you’re using an earlier release: 1) Load jQuery, define $ and set $ back to null before loading OpenLayers: JQ = $; $ = null; 2) Pass a string as an ID to the map constructor: var map = new OpenLayers.Map(‘map’) rather than var map = new OpenLayers.