Why won't this work? All I did was put it inside a "while" loop $(document).ready(function(){ var i = 1; while(i <= 9){ $(".mp-men" + i).click(function(){ $("#display").attr("src", "01-bigthumb-" + i ".jpg"); }); ++i; } }); Code (markup):