I have this working code but am not sure how to create a proper loop.
Looking for a way to create a function where one mousesovers an #id in a list element and doing so changes the url source of #mainImage to the one in the imgUrl array.
using forEach seems like a good option and am having problems setting it up.
var imgUrl = []; imgUrl[0] = "url 1"; imgUrl[1] = "url 2"; imgUrl[2] = "url 3"; imgUrl[3] = "url 4"; imgUrl[4] = "url 5"; imgUrl[5] = "url 6"; imgUrl[6] = "url 7"; (document).ready(function() { // mouse over ids in list $("#id-1").mouseover(function() { $("#mainImage").attr("src", imgUrl[0]) }); //mouse over 2 $("#id-2").mouseover(function() { $("#mainImage").attr("src", imgUrl[1]) }); //mouse over 3 $("#id-3").mouseover(function() { $("#mainImage").attr("src", imgUrl[2]) }); }); <div class="main"> <img id="mainImage" src="url"> </div> <ul class="menu"> <li><a href="#" id="id-1">one</a></li> <li><a href="#" id="id-2">two</a></li> <li><a href="#" id="id-3">three</a></li> <li><a href="#" id="id-4">four</a></li> <li><a href="#" id="id-5">five</a></li> <li><a href="#" id="id-6">six</a></li> <li><a href="#" id="id-7">seven</a></li> </ul>