Reputation: 68710
// 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!
Upvotes: 0
Views: 7739
Reputation: 5264
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'));
}
});
Upvotes: 2
Reputation: 41832
In your blur function, you have $this, but it is never defined. You only defined it in the scope of the focus() function.
Upvotes: 3