 <p>You can do that :</p> <pre><code>$('#btnDining').css({'cursor':'pointer'}).on('click', function(e){ var src = $(this).attr('src'); src = (src.indexOf('off.png')!=-1)?src.replace("_off","_on"):src.replace("_on","_off"); $(this).attr('src', src); }); </code></pre> <p>And I think, it's a more readable way..</p>