Home > jquery > How to avoid that the jQuery file loads after a custom js file? Sometimes I got $ not defined?

How to avoid that the jQuery file loads after a custom js file? Sometimes I got $ not defined?

June 14Hits:1
Advertisement

I have add in the master a jQuery registration and a custom js file in the header. After the custom js file I start running a function which is existing in my custom js file. Sometimes I got the error:

$ not defined

It looks like it is depending on the performance. Maybe the order is not OK. How to avoid this error?

<head> <script src="HERE SOME PATH/jquery-1.9.1.min.js"></script> <script src="HERE SOME PATH/myCustom.js"></script> 
<script type="text/javascript">         $(window).bind("load", function () {             jQuery(function () {                 jQuery.scrollDepth();             });         });     </script> </head> 

Answers

Use jQuery(window).bind instead of using $(window).bind.

See jQuery.noConflict(). Could other javascript libraries on your page be using the $ variable?

$ is just a variable that is used to alias jQuery and being a variable, anything could be assigned to it.

Try putting your custom.js and jquery-1.9.1.min.js at the bottom of the page, so that it loads first.

And also why not try loading your function like:

$(document).ready(function () {
  StartCustomFunction();
});

Related Articles

  • How to avoid that the jQuery file loads after a custom js file? Sometimes I got $ not defined?June 14

    I have add in the master a jQuery registration and a custom js file in the header. After the custom js file I start running a function which is existing in my custom js file. Sometimes I got the error: $ not defined It looks like it is depending on t

  • yum command not loading packages from custom .repo file on CentOS 6July 25

    I added a this .repo file in /etc/yum.repos.d/ on CentOS 6. Then when I try to install package from this repo I do not see the mirrors loaded from this repo. Output of yum repolist is Loaded plugins: fastestmirror Loading mirror speeds from cached ho

  • Why do binary files load quicker than alphanumeric text files?July 25

    I've noticed that when I load/store large data files in a binary format, the program runs much faster than if I load data from an ASCII encoded file. Why is this the case? The data in my case is plain, with limited parsing involved other than read()

  • Rsyslog outputting to custom log fileAugust 2

    Can anyone tell me what I did wrong here? Here is the ultimate question: Why when I use the logger command can I not get it to output to a custom log file in /var/log? In my script: logger -i -t ANM -p local7.info "This is a local 7 test" In the

  • Custom jQuery code loaded but not workingOctober 20

    I am trying to implement some custom jquery code for a 3D menu on my Drupal 7 site. I created two .js files one with the code and other one calling it on page. I have succesfully loaded both .js files throug my theme's .info file, however nothing hap

  • Reduce Your jQuery Script Loading Times

    Reduce Your jQuery Script Loading TimesMay 4

    Hi guys, I've stumbled upon a jQuery script that reduces the loading time of your JavaScript include files. It works by loading all your dot js files at the same time inside an array. I've tried the tests out and it does seem to load much quicker tha

  • jQuery not Loading for "Anonymous" UsersJune 27

    For Drupal 7, a jQuery will not load for "anonymous" users on any template pages. But when I log in as an administrator it loads. It's similar to this issue: http://drupal.org/node/802432, but nothing I tried has worked. The only way I could get

  • force jQuery to load in the headMarch 22

    I've written a plugin which uses wp_enqueue_script("jquery"); to load jQuery. I need to load jQuery in the head and not at the bottom of the body. However, I think that this command is overwritten by some theme which loads jQuery at the bottom o

  • How to force jQuery to load as a first script in header in frontend?July 17

    How to force jquery to load as a first script in header? Right now it's the last ;( like: <link type="text/css" rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css"

  • Loading custom language file for pluginJune 11

    I'm trying to load a custom language file for a plugins to avoid any changes for this file when updating the plugin. I tried several snippets in the functions.php of the theme, but none of them worked. add_filter('load_textdomain_mofile', 'custom_loa

  • Loading div sections from separate filesSeptember 29

    I am loading divs from separate HTML files into a div on the index.html page. This is being done using jQuery's .load(). There is however, a lot of repetition and I'm wondering if there is a cleaner way to achieve this. The HTML: <nav class="menu-

  • Program to load coordinates from a text file and display them on OpenStreetMap maps

    Program to load coordinates from a text file and display them on OpenStreetMap mapsOctober 6

    I have coordinates and wrote a program to create a VIK file to display them. I am looking for another (open-source) tool that loads coordinates from a text file I can create and display them on OSM maps. Now I use Viking to display some points and I

  • Jquery ajax to custom php file: returning blank dataMarch 18

    I created a custom php file, put it in my folder. The files does insert some data to the database to a custom table i created. require wp_path() . "/wp-load.php"; global $wpdb; $favorite_table = $wpdb->prefix . "fav"; $wpdb->inse

  • I need to load my custom js files dynamically using JavaScriptMarch 20

    from my SharePoint master page, I need to load my custom js files dynamically using JavaScript, I found the following methods on internet, what is the best way to do this ask: Using element.appendChild() to append the script or link elements: http://

  • Load an OpenGL buffer from fileJune 5

    The function's job is to load a vertex attribute buffer or an element buffer from a specified path, and upload it to OpenGL. Also, optionally, return the number of vertices/indices loaded through an output parameter. Signature: GLuint loadBufferFromF

  • Multiple selec2.js file loaded by several pluginsJune 8

    Since upgrading to WP 4.2.2, I have the following error in one of my js file : Uncaught TypeError: jQuery(...).select2 is not a function I google the issue and it seems that this can happen when several jquery are loaded. However, looking in the diff

  • Prevent other versions of jquery from loading on static front pageJuly 27

    This site is using cordillera which calls on /wp-includes/js/jquery/jquery.js?ver=1.11.2. The child theme contains a front-page.php which consists of: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/x

  • Loading only single language JSON file in Angular multilaguageJanuary 29

    I am working on ionic application. I want to add multi-language support for the same using language .json files. So I googled it and found few examples for loading files using "angular static file loader plugin", but it loads all the language fi

  • how to create own cache for file loading from disk to memory in c++ framwork?February 17

    how to create own cache for file loading from disk to memory in c++ framwork,I do not want to use windows cache ,because some of case windows cache does not gives the good results ? Is there any plugin in c++ I can directly use for multiImport of fil

  • Trying to open .eml files loads the entire email client, not the fileAugust 21

    I use Outlook Express on WXP with SP3. I'd been trying different email clients that associated .eml files with them, and eventually used folder options to change the association back to OE. At first, the files opened normally, but after a short while

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 1.100 s.