Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: $ is not a function WordPress

I might have an error in a .js document in a theme I have purchase:

$('.tagcloud a').wrap('<span class="st_tag" />'); 

I am trying to solve it but I am not a programmer so I don't know how. The site is this: http://www.framerental.com .

like image 678
user1645326 Avatar asked Sep 04 '12 06:09

user1645326


People also ask

Is not a function error in WordPress?

$ is not a function WordPress error occurs when the code comes before the jQuery library. For example, if a plugin or theme calls a code before calling the right library, you get this error. By default, WordPress doesn't understand $ as jQuery and you have to make some modifications to fix this error.

Is not a function TypeError is not a function?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.

Is not a function in '$( document )' '$' is undefined?

This is a common JavaScript error that happens when you try to call a function before it is defined. You get this error when you try to execute a function that is uninitialized or improperly initialized . It means that the expression did not return a function object.


2 Answers

You use jQuery.noConflict(); So $ is undefined.

You can read more about it here docs

Try to modify your code in this way (add $ sign to ready function):

jQuery(document).ready(function($) {     // Code that uses jQuery's $ can follow here. }); 
like image 100
jurka Avatar answered Sep 18 '22 16:09

jurka


Function errors are a common thing in almost all content management systems and there is a few ways you can approach this.

  1. Wrap your code using:

    <script>  jQuery(function($) {  YOUR CODE GOES HERE  }); </script> 
  2. You can also use jQuery's API using noConflict();

    <script> $.noConflict(); jQuery( document ).ready(function( $ ) { // Code that uses jQuery's $ can follow here. }); // Code that uses other library's $ can follow here. </script> 
  3. Another example of using noConflict without using document ready:

    <script> jQuery.noConflict();     (function( $ ) {         $(function() {              // YOUR CODE HERE         });      }); </script> 
  4. You could even choose to create your very alias to avoid conflicts like so:

    var jExample = jQuery.noConflict(); // Do something with jQuery jExample( "div p" ).hide(); 
  5. Yet another longer solution is to rename all referances of $ to jQuery:

    $( "div p" ).hide(); to jQuery( "div p" ).hide();

like image 26
Simon Hayter Avatar answered Sep 22 '22 16:09

Simon Hayter