Treehouse: Grow your CSS skills. Land your dream job.

Help with Rollover Image Swap!

  • # May 23, 2010 at 12:49 am


    So I’m a newbie at JavaScript, and I’m having trouble using JavaScript to enable a mouseOver, mouseOut code. I am attempting to replace an image with another image.

    Here is my code:

    < ?xml version = "1.0" encoding = "utf-8"?>
    < !DOCTYPE html PUBLIC = "-//W3C//DTD XHTML 1.0 Strict//EN" "">

    TAH Background Essays for Students Image

    Can anybody please help me? I do not get what I am doing wrong.

    # May 23, 2010 at 8:05 pm

    Try something like this.

    the html:

    <div id="mydiv">

    The css:

    #mydiv {

    background-image: img1.jpg;


    #mydiv:hover {

    background-image: img2.jpg;


    No javascript required ;)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.