Keeping conflicts out!
Because WordPress and jQuery are anticipating other libraries to be loaded which may use the short variable, $
. The wp_enqueue_script
ensures jQuery is loaded up in noConflict
mode. Therefore, you'll also need to make sure to write your custom jQuery code in noConflict
mode's syntax. The easiest way to do this is to replace the $
variable (common in many jQuery scripts) with the full jQuery
variable, as I've discussed in Chapter 1, Getting Started: WordPress and jQuery, and done in my two previous samples.
Setting your own jQuery variable
If you find the jQuery
variable tedious to write out, yet want to remain in noConflict
mode, you can replace the standard $
variable to any variable you want as follows:
<script type="text/javascript"> var $jq = jQuery.noConflict(); $jq(document).ready(function() { $jq("p").click(function() { alert("Hello world!"); }); }); </script>
But I really want to use the $ variable!
You should not use the $
variable for jQuery within...