Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 538 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wordpress how to use jquery and $ sign

#1
I have a simple jQuery script in a WordPress plugin that is using a jQuery wrapper like this:

$(document).ready(function(){

// jQuery code is in here

});



I am calling this script from within the WordPress Dashboard and am loading it AFTER the jQuery framework has loaded.

When I check the page in Firebug I constantly keep receiving the error message:

> TypeError: $ is not a function
>
> $(document).ready(function(){

Should I maybe wrap the script in this function:

(function($){

// jQuery code is in here

})(jQuery);

I have had this error quite a few times and am not sure how to handle it.

Any help would be greatly appreciated.
Reply

#2
By default when you enqueue jQuery in Wordpress you must use `jQuery`, and `$` is not used (this is for compatibility with other libraries).

Your solution of wrapping it in `function` will work fine, or you can load jQuery some other way (but that's probably not a good idea in Wordpress).

If you must use `document.ready`, you can actually pass `$` into the function call:

jQuery(function ($) { ...
Reply

#3
Try this:

<script language="JavaScript" type="text/javascript" src="jquery/jquery.js"></script>
<script>
jQuery.noConflict();
(function ($) {
function readyFn() {
// Set your code here!!
}

$(document).ready(readyFn);
})(jQuery);

</script>
Reply

#4
You can avoid confliction like this

var jq=jQuery.noConflict();
jq(document).ready(function(){
alert("Hi this will not conflict now");
jq('selector').show();
});
Reply

#5
Double check your jQuery references. It is possible that you are either referencing it more than once or you are calling your function too early (before jQuery is defined). You can try as mentioned in my comments and put any jQuery reference at the top of your file (in the head) and see if that helps.

If you use the encapsulation of jQuery it shouldn't help in this case. Please try it because I think it is prettier and more obvious, but if jQuery is not defined you will get the same errors.

In the end... jQuery is not currently defined.
Reply

#6
You have to pass $ in function()

<script>
jQuery(document).ready(function($){

// jQuery code is in here

});
</script>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through