jQuery check if it is clicked or not

后端 未结 6 1335
失恋的感觉
失恋的感觉 2020-11-29 02:19
$( element ).click( function() {

});

How can I check if the element is clicked or not? I\'m doing like that

function element() {
         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 02:22

    Using jQuery, I would suggest a shorter solution.

    var elementClicked;
    $("element").click(function(){
       elementClicked = true;
    });
    if( elementClicked != true ) {
        alert("element not clicked");
    }else{
        alert("element clicked");
    }
    

    ("element" here is to be replaced with the actual name tag)

提交回复
热议问题