I would like to turn the jquery code below into a function so that I can add links to the list and not touch jquery. I assume that I will need to put the image name in the <a href> tag somewhere.
html code
<img id="storyimg" src="1.png" alt="img" /> <ul class="sb_menu"> <li><a href="linkpage.htm" class="newslink1">Link 1</a></li> <li><a href="linkpage.htm" class="newslink2">Link 2</a></li> <li><a href="linkpage.htm" class="newslink3">Link 3</a></li> </ul>
JQuery
$('a.newslink1').bind('mouseover', function() { $('img#storyimg').attr("src", "1.png"); }); $('a.newslink2').bind('mouseover', function() { $('img#storyimg').attr("src", "2.png"); }); $('a.newslink3').bind('mouseover', function() { $('img#storyimg').attr("src", "3.png"); });
josh source share