简体   繁体   中英

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

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';
});
$("#signin").click(function(e) {
    e.preventDefault();
    $(this).attr("src", "images/icon.png");
});

.attr <- Function name is lowercase.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM