var exposure = 20; var input_index = 0; function setpic() { $("#pic").attr("src", exposure + "/" + files[input_index]); } $(function() { setpic(); }); Mousetrap.bind('z', function() { $("#pic").toggleClass("fit_view"); });