Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir,

<img src="rk.jpg" alt="rajkumar" class="imgh"></img>

this is my image, i want to do chane img src whene mouse moves on this image.

.imgh:hover
{

}

i want to change img src with the help of hover.

plz help....
Posted
Comments
Sergey Alexandrovich Kryukov 25-Apr-14 8:06am    
Why not using Javascript?
—SA
Rajkumar_007 25-Apr-14 8:12am    
I dont know javascript in deapth.

Simply try this.
HTML
<img src="rk.jpg" alt="rajkumar" class="imgh" onmouseover="this.src='your image name';" onmouseout="this.src='rk.jpg';"></img>


Hope it helps :)
 
Share this answer
 
Comments
Rajkumar_007 25-Apr-14 8:41am    
thank u sir... :)
Sanket Saxena 25-Apr-14 8:43am    
Most Welcome :)
This really is a task that requires javascript, and it's not a complex task either and can be done without "in-depth" knowledge.

However, if you want a look-alike solution using pure css, try changing the img to a div, using css to set display: block and the width and height to the size of your picture. Then place the picture there with background-image, and modify that property on mouseover.
 
Share this answer
 

Solution


Use jQuery[^], which makes life easier.

Code


JavaScript
$(document).ready(function () {
    $('.imgh')
        .mouseover(function () {
        $(this).attr("src", "http://taditdash.files.wordpress.com/2014/01/tadit-dash.jpg");
    })
        .mouseout(function () {
        $(this).attr("src", "http://s.codeproject.com/App_Themes/CodeProject/Img/logo250x135.gif");
    });
});

NOTE:
  1. Mark that I have assigned the Image URLs to the source attribute.
  2. To run jQuery, you have to include the jQuery file in the head section of your WebPage.
  3. You can download from here[^].
    Else you can directly use the online latest version like...
    HTML
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

Demo


[Demo] Change Image Source on Mouse Hover[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900