How to see if you're clicking the same element twice? Jquery

血红的双手。 提交于 2019-11-30 21:06:04

You can't compare jQuery objects, but you can compare the DOM objects they contain. Try this:

var previousTarget=null;
$("a").click(function() {
    if(this===previousTarget) {
        alert("You've clicked this element twice.");
    }
    previousTarget=this;
    return false;
});

You may try this,

var _oldthis = null;
$('div').click(function(){
  var _this = $(this);

  if(_this == _oldthis) {
    alert('You clicked this last');
    _oldthis = null;
    return false;
  }
  _oldthis = _this;

});

Owen Bula
var clickHandler;
$('a').click(function(){
    if(clickHandler) {
        clickHandler = alert('click twice');
    } else {
        clickHandler = alert('click once');
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!