I have a question about ordering my jquery code. I have a list of images, each of which has a unique identifier, and the click event displays a larger image and its information. Is there a way to do this with a loop similar to php foreach loop?
$(function() { $('img#cl_1').click(function() { $('div#left').html('display image').slideDown('fast'); $('div#right').html('display image info').slideDown('fast'); }); $('img#cl_2').click(function() { $('div#left').html('display image').slideDown('fast'); $('div#right').html('display image info').slideDown('fast'); }); $('img#cl_3').click(function() { $('div#left').html('display image').slideDown('fast'); $('div#right').html('display image info').slideDown('fast'); }); $('img#cl_4').click(function() { $('div#left').html('display image').slideDown('fast'); $('div#right').html('display image info').slideDown('fast'); }); });
source share