function bginput_init(domChunk){ if (typeof domChunk != 'string' || domChunk == '') { domChunk = 'input[emptybg]'; } $(domChunk).focus(function() {bgImageUpdate.call(this, 'focus');}); $(domChunk).blur(function() {bgImageUpdate.call(this, 'blur');}); $(domChunk).each(function(){ bgImageUpdate.call(this, 'blur'); this.style.backgroundRepeat = 'no-repeat'; }); } function bgImageUpdate(func) { if (func == 'focus') { this.style.backgroundImage = ''; } else if (func == 'blur'){ if (this.value == '') { this.style.backgroundImage = "url('"+$(this).attr('emptybg')+"')"; } else { this.style.backgroundImage = ''; } } }