jQuery check if it is clicked or not

后端 未结 6 1324
失恋的感觉
失恋的感觉 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:29

    This is the one that i've tried & it works pretty well for me

    $('.mybutton').on('click', function() {
           if (!$(this).data('clicked')) {
               //do your stuff here if the button is not clicked
               $(this).data('clicked', true);
           } else {
               //do your stuff here if the button is clicked
               $(this).data('clicked', false);
           }
    
       });
    

    for more reference check this link JQuery toggle click

提交回复
热议问题