javascript - Cancel click handler from mousedown handler -



javascript - Cancel click handler from mousedown handler -

i’m trying prevent click handler firing based on status within mousdown handler same element. consider this:

var bool = true; $('button').click(function() { console.log('clicked'); }).mousedown(function(e) { bool = !bool; if ( bool ) { // temporary prevent click handler, how? } });

is there neat way cross-communicate between handlers? here bin: http://jsbin.com/ipovon/1/edit

this works, although, i'm not sure it's quite reply looking for. it's double click function, if set bool=false; initially.

var bool = true; $('button').mousedown(function(e) { bool = !bool; if ( bool ) { $(this).unbind('click'); } else { $(this).click(function(){ console.log('clicked'); }); } });

update

also, pull click function out of mousedown this, if like:

var bool = true; function buttonclick(){ console.log('clicked'); } $('button').mousedown(function(e) { bool = !bool; if ( bool ) { $(this).unbind('click'); } else { $(this).click(buttonclick); } });

javascript jquery events handlers

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -