$(document).ready(function() { var split = /^(.*\/)([^/]*)$/.exec($('#yn-boo').attr('src')); if (split && (split[2] === 'default.png' || split[2] === 'sleep.png')) { $('#yn-boo') .nextAll('.z0').attr('src', 'http://www.mirari.fr/qiKe').end() .nextAll('.z1').attr('src', 'http://www.mirari.fr/SpkR').end() .nextAll('.z2').attr('src', 'http://www.mirari.fr/jX5K').end() .attr('src', split[1] + 'pixel.png'); } });