Clear background if content present in textarea jQuery

0 votes

Please see this jsFiddle: https://jsfiddle.net/Wmq6f/

I have a textarea that has a background image, it is removed on 'focus' and restored on 'blur' but when the content is present in the textarea it should not show in either case, but I can't achieve that with this jQuery:

$('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'));
    }
});

Thanks for your help

Jul 22 in Web Development by gaurav
• 17,580 points
16 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Web Development

0 votes
0 answers

If/else else if in Jquery for a condition

I am having a set of text ...READ MORE

Jul 1 in Web Development by gaurav
• 17,580 points
14 views
0 votes
0 answers
0 votes
0 answers

How to show message in model body if bootstrap model have no data in jquery

I'm trying to display a text message ...READ MORE

Jul 29 in Web Development by gaurav
• 17,580 points
13 views
0 votes
0 answers
0 votes
0 answers

Meaning of if(something.length) in jQuery

I was parsing some smooth-scrolling code online ...READ MORE

6 days ago in Web Development by gaurav
• 17,580 points
8 views
0 votes
1 answer

How do write IF ELSE statement in a MySQL query

You probably want to use a CASE ...READ MORE

answered Feb 18 in Web Development by Aditya
• 7,300 points
20 views
0 votes
1 answer

How to focus on a form input text field on page load using jQuery?

In this example the form input text ...READ MORE

answered Jun 21 in JQuery by rajatha
• 7,040 points
15 views
0 votes
0 answers

Get the value in an input text box

What are the ways to get and ...READ MORE

Jun 29 in Web Development by gaurav
• 17,580 points
15 views
0 votes
0 answers

Get the value in an input text box

What are the ways to get and ...READ MORE

Jun 30 in Web Development by gaurav
• 17,580 points
7 views
0 votes
1 answer

jQuery text animation "explosion" effect on hover

The logic: Wrap each textual character inside a <span> tag Make ...READ MORE

answered Aug 4 in Web Development by rajatha
• 7,040 points
10 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP