Search code examples
javascriptcsshtmlmouseovermouseout

Hiding and displaying an image in mouse over action in a div


Im trying to hide a specific image in mouse over and display another image. The opposit will be done when mouseout. Below is the code I wrote,

<div id="console" onmouseover="$(this).find('#offer_image').css({display: none});$(this).find('#offer_image_selected').css({visibility: visible});"
     onmouseout="$(this).find('#offer_image').css({visibility: visible});$(this).find('#offer_image_selected').css({display: none});" >

But it doesn't work when I run the application. Can anyone point out what has gone wrong in it?
Thanks a lot!


Solution

  • If your using jQuery try

    <div id="console"
         onmouseover="$(this).find('#offer_image').hide(); $(this).find('#offer_image_selected').show();"
         onmouseout="$(this).find('#offer_image').show(); $(this).find('#offer_image_selected').hide();">
    

    This uses show() and hide() methods from jQuery.

    Otherwise use the following:

    <div id="console"
         onmouseover="$(this).find('#offer_image').css('display', 'none'); $(this).find('#offer_image_selected').css('display', 'block');"
         onmouseout="$(this).find('#offer_image').css('display', 'block'); $(this).find('#offer_image_selected').css('display', 'none');" >