submit button rollover not working

Posted on 2011-05-02
Last Modified: 2012-05-11
I have a submit button at the end of a form.  The button has an image  that I want to change when it's rolled over.  It seems like the first code below should work.  The <img> tag below the button does change when it's rollover over, and it's exactly the same markup as is in the button code. .  So why doesn't the button image change when it's rolled over?.  

 <button id="buyNow" type="submit"><img src='images/buynowButton.jpg' onmouseover="src='images/buynowButton_hover.jpg'" onmouseout="src='images/buynowButton.jpg'" alt="buynowButtons"/></button>

<img src='images/buynowButton.jpg' onmouseover="src='images/buynowButton_hover.jpg'" onmouseout="src='images/buynowButton.jpg'" alt="buynowButtons"/>

Thanks for any ideas.
Question by:steva
    LVL 22

    Accepted Solution

    Hi steva,
    The reason it's not working in the button is due to the fact that the mouseover event of the button is overriding its image event, since it's a button element, the mouse events are exclusive and you would have to modify your code to call the onmouseover and onmouseout events of the button itself rather than the image.

    For example:
    <button id="buyNow" type="submit" onmouseover="this.firstChild.src=''" onmouseout="this.firstChild.src=''"><img src='' alt="buynowButtons"/></button>

    Open in new window

    Your code should be as below
    <button id="buyNow" type="submit" onmouseover="this.firstChild.src='images/buynowButton_hover.jpg'" onmouseout="this.firstChild.src='images/buynowButton.jpg'"><img src='images/buynowButton.jpg' alt="buynowButtons"/></button>

    Open in new window


    Author Closing Comment

    PERFECT!   Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    I starting with php 11 68
    Strange space issue in Chrome browser 8 52
    CSS menu problem 2 26
    Dynamically changing javascript code 2 24
    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now