Jquery onclick on div

前端 未结 6 1482
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 09:04

I have a simple question. The following code works for all the tags:

$(\'*\').click(function(e) {  
    alert(1);
});

But, when I try this

6条回答
  •  独厮守ぢ
    2021-01-01 09:25

    Nothing.

    $('#content').click(function(e) {  
        alert(1);
    });
    

    Will bind to an existing HTML element with the ID set to content, and will show a message box on click.

    • Make sure that #content exists before using that code
    • That the ID is unique
    • Check your Javascript console for any errors or issues

提交回复
热议问题