views:

38

answers:

2
// Clearing Textarea
$('textarea').focus(function() {
   var $this = $(this);
   $.data(this, 'img', $this.css('background-image'));
   $this.css('background-image', 'none');
});
$('textarea').blur(function() {
    if($.trim($('textarea').val()).length){
         $this.css('background-image', 'none');
    } else {
        $(this).css('background-image', $.data(this, 'img'));
    }
});

When I click out of the textarea, and although there is content present in it, I still see the background image.

Thanks for your help!

+3  A: 

In your blur function, you have $this, but it is never defined. You only defined it in the scope of the focus() function.

Matt
A: 

Adding to what Matt said. $this wasn't defined. What you needed to do was $(this):

$('textarea').blur(function() {
  if($.trim($('textarea').val()).length){
    // Added () around $this
    $(this).css('background-image', 'none');
  } else {
    $(this).css('background-image', $.data(this, 'img'));
  }
});
Hooray Im Helping