• I am about to pull my hair out with this one and I have looked all over the internet, the ‘Using Javascript’ page here, in WordPress, and all over the support forums but none of the suggestions help.

    I have a very simple script that creates a collapsible area in my page. Now, it works perfectly outside of WP here:
    https://www.noggaddicts.com/Untitled-6.php
    but when I actually insert that into my page such as here:
    https://www.noggaddicts.com/?p=190

    Now, I’ve tried to make it work by typing out:

    <script type="text/javascript" src="/js/toggle.js">
    <!--
    toggleBB(patch201, bbArrow01);
    //--></script>

    instead of just:

    <script type="text/javascript">
    <!--
    toggleBB(patch201, bbArrow01);
    //--></script>

    I’ve tried changing the javascript URL from absolute to relative, to full URL, to actually typing out the script in the header and none of that works. It’s like the script is not being run, at all.

    Here’s the script, which is the contents of the toggle.js:

    function toggleBB(srcElement, srcArrow) {
    if (srcElement.style.display == "none") {
    srcElement.style.display = "";
    srcArrow.src = "/images/expand.gif";
    } else {
    srcElement.style.display = "none"
    srcArrow.src = "/images/collapse.gif";
    }
    }

    Any help on this would be greatly appreciated.

    Edit:
    To clarify and expand on what troubleshooting I’ve done:
    I have Rich Editor turned off.
    I use Script Enabler plugin.
    I use Text Control and I turned off formatting and texturization.

    The code looks perfect when I look at the source, but it’s just not being run.

    I also tried putting in the code outside of a post, in my sidebar to see if it was something to do with it being in the post and it does the exact same thing, which is nothing.

Viewing 4 replies - 1 through 4 (of 4 total)
  • If you’re using an external file (toggle.js) with that first <script> call, you don’t want to also include the <!-- toggleBB(patch201, bbArrow01); //--> part. All you want is to give wp the path to the external file – and you *might* have to use the absolute url for the file instead of a relative one….

    Thread Starter rilus

    (@rilus)

    Well, I need that piece of code (<!-- toggleBB(patch201, bbArrow01); //-->) there because I need the script to run through that function, right there and then.

    Well, gee…. I don’t see anything really wrong with it then…. and you’ve tried an absolute addy too…. huh. I’m out of ideas then, hopefully someone brighter than I about js will be along to help out.

    Thread Starter rilus

    (@rilus)

    I hope so. I am really baffled by this. I assumed that as long as the javascript was properly rendered on the site, it would run without problems, but this doesn’t seem to be the case.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Do some Javascripts not work in WP, at all?’ is closed to new replies.