Well, I’m working on WordPress Theme and I’ve a very strange behavior.
When I put my jQuery script in script tag (anywhere on the site) it works like charm.
But when I try to link to a file with the same script, like:
<script src="address" type="text/javascript"></script>
– it doesn’t.
What’s wrong? The link is VALID. The script was tested in the beginning but also at the end of a site (so that’s no “on load” problem).
How to troubleshoot problems like that? Is there a way to debug JavaScript in Opera?
Can’t provide a link.
Thanks
a javascript file should ends with
.js
, probably path and especially file name is wrongtake a look at firebug (or opera console) if this get returns a 404 error
Like @Fabrizio Calderan said, maybe the script URL is wrong? Or maybe because of lack of
js
extension server doesn’t send proper mime type and browser has a problem with interpreting the file.Also if it’s wordpress, you probably rewrite post’s URLs somehow – if the script is in your domain’s root directory you should put
/
before filename, if it’s in a template directory try what @Nick Pyett proposed.Yes, you can debug JavaScript in Opera – check out Opera Dragonfly
You need to use the wp_enqueue_script() function. More here http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Unfortunately you all were wrong, the answer was:
$(something) works only inline and when embedded – WordPress accepts only jQuery instead of the dollar sign, so everything works fine after changing all “$” to “jQuery” 🙂
Anyways thanks! 🙂
Assuming your script is a .js file, is in your template folder and the line is being included between the html head tags…
Check the trailing slash after the php because i can’t remember if the function includes one off the top of my head.
If you go to View – Developer Tools and check Opera Dragonfly, you will see Dragonfly open in the bottom of the browser, which appears to have similar capabilities to Firebug for Firefox (DOM browser, Network monitor, Script debugger, etc). This may help you get to the root of your problem.