svd
svd

Reputation: 43

Change Image on image click event in Jquery

i am not able to change image on clicking image in jquery pls see this

$("#signin").click(function (event) {
    event.preventDefault();
    alert("show data");
    $("#signin").Attr('src', 'images/icon.png');
});

Upvotes: 2

Views: 159

Answers (3)

mat
mat

Reputation: 1378

$("#signin").click(function(e) {
    e.preventDefault();
    $(this).attr("src", "images/icon.png");
});

.attr <- Function name is lowercase.

Upvotes: 1

Anton
Anton

Reputation: 32581

You need to change

.Attr 

to

.attr

.Attr is not a function in jQuery, it's case sensitive.

Documentation : http://api.jquery.com/attr/

Note: You could use this.src there is no need to use jQuery to change the source of the image

$("#signin").click(function (event) {
    event.preventDefault();
    alert("show data");
    this.src= 'images/icon.png';
});

Upvotes: 1

Adil
Adil

Reputation: 148120

You have mis-spelled the function attr(). The Attr should be attr, javascript is case sensitive.

$("#signin").click(function (event) {
    event.preventDefault();
    alert("show data");
    $("#signin").attr('src', 'images/icon.png');
});

Upvotes: 0

Related Questions