We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25076
    • 3 Posts
    Hi guys,

    I’m trying to get a background-image swapping jQuery script to work in MODx but no luck so far. You can see how it *should* work on a static page here:

    http://www.abeldesign.com/halltoll/konferanse.html

    If you click on the 1-4 icons in the bottom right it swaps the background image, which is what I want. However, when i try this within MODx, it redirects the site to the home page. The code is thus:

    $(".bgSwapper1").click(function(){
    $(’.konferansePage #contentWrapper’).css(’background-image’, ’url(img/konferansePage_bg.jpg)’); return false;
    });

    $(".bgSwapper2").click(function(){
    $(’.konferansePage #contentWrapper’).css(’background-image’, ’url(img/konserterPage_bg.jpg)’); return false;
    });

    $(".bgSwapper3").click(function(){
    $(’.konferansePage #contentWrapper’).css(’background-image’, ’url(img/barPage_bg.jpg)’); return false;
    });

    $(".bgSwapper4").click(function(){
    $(’.konferansePage #contentWrapper’).css(’background-image’, ’url(img/restaurantPage_bg.jpg)’); return false;
    });

    For some reason beyond my (limited) comprehension, the return false is not working for the image swap functions when in MODx, although it actually DOES work on the other function on the page which you can see if you click the little yellow arrow at top right of the red overlay section:

    $(".slideToggle").click(function(){
    $(".hideSlide").slideToggle("slow");
    $(this).toggleClass("toggy"); return false;

    });


    I have no idea why it should work in the latter but not the former. Maybe I’m missing something massively obvious (probably) but if anyone could help me I’d be very grateful.

    Cheers,

    Rik

      • 4310
      • 2,310 Posts
      You need a plugin to stop the # href redirecting to the home page.
      Can’t find the one I normally use in the repository but here’s another
        • 25076
        • 3 Posts
        Thanks for that. The page is now no longer redirecting, but the script still doesn’t work... hm...
          • 4310
          • 2,310 Posts
          OnWebPagePrerender is the usual one wink

          EDIT : turns out this is the plugin I use!
            • 25076
            • 3 Posts
            So I finally realised that it was ME being an idiot - I forgot to wrap the functions in a $(document).ready(function(){ on the MODx site. D’oh! All now working perfectly. Thanks again for the plugin info!