Rahul Singh
Rahul Singh

Reputation: 1632

Change image attibute to using jquery

I have a block of code through which I am changing the title of input as span. next to that is my image though which is set as display hidden.

<div class="field">
  <input type="text" name="email" class="w_def_text" id="email" title="Email*" />
  <img width="27" height="27" src="images/error.png" alt="Error">
</div>

I have changed this tiltle as span using jquery. Now I am sending input values on blur event.

like

$('#email').blur(function() {
var email = $('#email').val();
(1.)   $(this).next('img').show().html('<img width="80" height="27" src="images/dot.gif" >');
$.post('showuserstatus.php', {
    emailid: email
}, function(data) {
//$('#erroremail').show().html(data);
(2.)   $(this).next().next().html(data);

   });
});

At both the point I wish to change src of image, that is while sending response. And after receiving response.

NOTE : I have used .next.next because I have span in between both. So second next is for image.

Upvotes: 1

Views: 101

Answers (1)

sathis
sathis

Reputation: 547

Use

$(".field img").attr("src", "images/dot.gif");

Upvotes: 5

Related Questions