Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 938069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:34:52+00:00 2026-05-15T21:34:52+00:00

Posted this over at the Drupal forums but haven’t received a response. Basically, I

  • 0

Posted this over at the Drupal forums but haven’t received a response. Basically, I have a simple JavaScript item I developed for another website that I’m trying to port over into Drupal. It’s basically a div with three tabs stacked on top of each other and an image. When the user scrolls over a tab, the image changes (depending on the tab scrolled over).

The progress I’ve made is as follows.

$(document).ready(function () {

var imageOne = new Image(); imageOne.src = "images/slideshow/slideshow-image1.png";
var imageTwo = new Image(); imageTwo.src = "images/slideshow/slideshow-image2.png";
var imageThree = new Image(); imageThree.src = "images/slideshow/slideshow-image3.png";
var currentSlideshowImage = new Image();

$("#slideshow1").hover(
    function () {
        alert(imageOne.src);

        currentSlideshowImage = imageOne;
        document.getElementById("slideshow-image-object").src = currentSlideshowImage.src;
        document.getElementById('slideshow1').className = "active";
        document.getElementById('slideshow2').className = "";
        document.getElementById('slideshow3').className = "";
    }
);

$("#slideshow2").hover(
    function () {
        alert(imageTwo.src);

        currentSlideshowImage = imageTwo;

        document.getElementById("slideshow-image-object").src = currentSlideshowImage.src;

        document.getElementById('slideshow2').className = "active";
        document.getElementById('slideshow1').className = "";
        document.getElementById('slideshow3').className = "";
    }
);

});

Looking at the above code, there is a function attached to the hover event of two elements. For some reason, only the first event added will work. If I hover over slideshow1, the function calls as expected however slideshow2 does nothing. If I was to modify the code and move slideshow2 before slideshow1, the hover event on slideshow2 will run as expected however slideshow1 will do nothing.

Am I missing something simple here? Is this how I’d go about adding events to elements in my theme (this code is stored in an external file referenced in the .info theme file)? Any help at this point will be greatly appreciated.

Any ideas what’s going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:34:53+00:00Added an answer on May 15, 2026 at 9:34 pm

    JQuery.hover() requires two arguments: a function to call on ‘enter’ and another on ‘leave’. The problem arrives when you leave the element, JQuery tries to call on null and throw an error. Try this instead (I’ve also taken the liberty of cleaning up your code to avoid repeating… yes, your code has useless repetitions) :

    $(document).ready(function () {
    
    // { elementId: url, ... }
    var imgs = {
       'slideshow1': 'images/slideshow/slideshow-image1.png',
       'slideshow2': 'images/slideshow/slideshow-image3.png',
       'slideshow3': 'images/slideshow/slideshow-image3.png'
    };
    var currentSlideshowImage;  // no need to initialize now
    
    $.each(imgs, function(id,url) {
       var img = new Image(); img.src = url;
       $('#' + id).hover(
          function() {
             currentSlideshowImage = img;
             $('#lideshow-image-object').attr('src', img.src);
             $(this).addClass('active');
          },
          function() {
             currentSlideshowImage = null;  // no image selected ?
             $(this).removeClass('active');
          }
       );
    });
    
    });  // JQuery.ready
    

    You can add images to your slideshow using the convenient imgs object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.