I had some code that worked wonderful when it was inline. When I moved it to an external JS file, it stopped working and I cannot figure out why. So hopefully one of the bright people here can find my mistake.
I’m using jQuery and echoing the header of the webpage out via a PHP script, like so:
$(document).ready(function(){
//Hide div w/id extra
$("#rpg_games").css("display","none");
$("#tabletop_games").css("display","none");
$("#rpg").click(function(){
if ($("#rpg").is(":checked"))
{
$("#rpg_games").show("fast");
}
else
{
$("#rpg_games").hide("fast");
}
});
});
$("#mini").click(function(){
if ($("#mini").is(":checked"))
{
$("#tabletop_games").show("fast");
}
else
{
$("#tabletop_games").hide("fast");
}
});
});
For the life of me, I have no idea what I’m doing wrong. The hide.js file is located in the same directory as the PHP script, and when I echo out the code inline, it works fine. Yeesh.
More readable and PHP doesn’t have to scan the string for variables to parse as variables aren’t parsed in single quote strings - which makes it slightly faster as well (emphasis on slightly)
Perhaps there’s some mod_rewrite jiggery-pokery going on? Best thing is to do view-source with Firefox. See if the <script> tags are there. Then click the src links, and see if the correct JS appears. If not, then you know there’s a problem with where it’s located.
On the computer that your using do you have any script blocking software in use, which may be blocking the external script file, if so try whitelisting/allowing the file.
I have no clue why this works for me (on this one site), but if I break down and use an absolute path in my src, it works for some reason.
It’s strange, goes against all I thought I knew regarding sourcing…
For some reason this site I’m puttering on is a frigging path nightmare (only responds to absolute, except the line before which uses a relative. WTF?), but maybe that’ll work for you too.
Yeah, one of the first things I did was to check the page source. The script tags are most definitely being displayed correctly. Clicking on the src links loads the JS. So, yeah, I’m not sure what’s up with this.