Search code examples
javascriptfunctionhref

javascript change image and href


I have some code that properly changes an image based on which text the mouse hovers over. The page is here: http://www.acethelogicgames.com/javatest.html

If you hover over Facebook, the image turns into the facebook logo, and if you hover over Twitter, the image turns into the twitter logo. That part works fine.

My question is, how can I make the image contain a link to facebook.com when the Facebook logo appears, and make the image contain a link to twitter.com when the Twitter logo appears?

Thanks for any help you can provide!


Solution

  • function change(menuId, image, newImage, newUrl)
    {
        var img = document.getElementById(image);
        img.src = newImage;
        document.getElementById('d3').href = newUrl;
    }