Forums

jQuery problem (4 posts)

  1. MajinSaha
    Member
    Posted 7 months ago #

    Hello everyone!
    This is not really related to how wp files work, but rather to directory structure of WordPress installation.
    I created a simple html file (independent of WordPress) inside wp-content folder to test jQuery scripts that I am working on. I am using

    <script type="text/javascript" scr="jquery-whatever-version.js"></script>
    <script type="text/javascript" scr="blabla.js"></script>

    inside <head> tags of my file to load the script. These scripts won't load.
    However, the same file gives the expected results if copied to the home folder of WordPress. Both jQuery library and the script itself I am loading are copied along with this file to the same location.
    So I suppose there must be some magic that makes every folder beside home restrict script loading.
    But why? Can you explain what is going on? It doesn't influence my work anyhow, it is just a test file for learning how jQuery works. I also have been choosing whether to post this in WP forum or jQuery forum, and decided to choose the first one, since not everyone in jQuery community knows WordPress.
    Thanks for your answers.

  2. keesiemeijer
    moderator
    Posted 7 months ago #

    A safe way of adding javascripts to a WordPress generated page is to use wp enqueue script and use the $deps argument to tell it that your script depends on jquery. You put the wp enqueue script code in your theme's functions.php:
    http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_a_script_from_your_theme_which_depends_upon_a_WordPress_Script

  3. fyllhund
    Member
    Posted 7 months ago #

    or just link it correctly in html.

    wp-content/folder/folder/folder/jquery.js
    or wherever you placed the file.

    If you link like that html believes the file is in the wordpress folder aka

    localhost/yoursite/jquery.js

  4. MajinSaha
    Member
    Posted 7 months ago #

    I don't really know what happened but it works now. All I did I moved my files back to wp-content after they started working in the home folder (which is one level higher). I didn't change a slight bit in the code including paths.
    Maybe there's a bug in Firefox or whatever. Thanks for all the answers.

Reply

You must log in to post.

About this Topic