$(function() { $("a[rel^=prettyPhoto]").prettyPhoto(); $("span [rel=prettyimage]").bind('click', function(e) { el_id = $(this).attr('id').split('_'); images = pretty_images[el_id[1]]; $.prettyPhoto.open(images); return false; }); });