image src change on mouse over in jquery

piku picture piku · Aug 5, 2010 · Viewed 30.1k times · Source

html-

<img id="storyimg" src="images/stor.jpg" alt="img" />  
                <ul class="sb_menu">            
                    <li><a href="linkpage.htm" class="newslink1">Wireless Networking at Fortune Inn, Noida</a></li>
                    <li><a href="linkpage.htm" class="newslink2">18th International Conference on Oral & Maxillofacial Surgery</a></li>
                    <li><a href="linkpage.htm" class="newslink3">WiFi deployment at Vellore Institute of Technology</a></li>                        
                </ul>

I want when user moves over these li items I want to change the image like-

<script>
                $('a.newslink1').bind('mouseover', function() {
                $('img#storyimg').src("images/stor1.jpg");
...same for newslink2 and 3, image will be stor2 and 3

but this is not working i think i have written wrong jquery?????????

Answer

Sarfraz picture Sarfraz · Aug 5, 2010

Use attr:

$('img#storyimg').attr("src", "images/stor1.jpg");

More Info:

http://api.jquery.com/attr/