开发者

.click() on image does not work as expected

开发者 https://www.devze.com 2023-03-01 00:23 出处:网络
I am attempting to alert some text when an image is clicked. javascript code: $(document).ready(function() {

I am attempting to alert some text when an image is clicked.

javascript code:

$(document).ready(function() {
    $(".delRo开发者_运维技巧w").click('function() {
        alert("hello!");
    });
});  

html code:

<img src="../images/delete.png" alt="delete" class="delRow"></img>

This code seems straight forward; however, it is not working as expected. Are images handled differently when using .click?

-Thanks,

Rich


$(document).ready(function() {
    $(".delRow").click(function() {
        alert("hello!");
    });
});

WORKING DEMO


You have extra ' at click.(function(){

It should be

$(document).ready(function() {
    $(".delRow").click(function() {
        alert("hello!");
    });
});  


$(document).ready(function() {
    $(".delRow").click(function() {
        alert("hello!");
    });
}); 

Remove the " ' " before the second function

0

精彩评论

暂无评论...
验证码 换一张
取 消