JQuery - Switch mousedown event without destroying it in dom?

So, on Friday I asked this question and it was not well written, let me explain this in more detail:

So that may sound good, but I have this container in which I include the mousedown event, and all I want to do is switch it without destroying its properties.

If so:

$("#div").unbind("mousedown") // This will just destroy the event. 

I thought I could move the event to a dom element that is not in use? And then just return it when I finish ...

So here's what happens: I have a plugin that just lets you call it Vinny now

  $("#div").vinny(settings); 

vinny has a mousedown event that I want to enable / disable using a trigger.

I thought I would have a function $ fn.disableMouseDown that could disable it, but was curious if their way to untie mouseDown on dom but not destroy it?

If you know a quick way to do this, help me! Thanks Winnie

+4
source share
5 answers

Hey guys, thanks for all the ideas, but I kind of made a hacky approach to this.

I explain z:

So, this plugin on mousedown is bound in plugin.init (), and in them I defined a local function that checks disableValue, and in them I just check dom for a or do bool return and run it against another function that was already present when the event exited mousedown.

Make sense? I hope so too.

Thanks,

0
source

Put your command inside the function so that you can only bind / untie with one line, i.e.

 function some() { // some commands } $("#div").bind("mousedown", some); $("#div").unbind("mousedown"); 
+4
source

One approach is to simply use a named function, bind it when needed, and undo it if it is not:

 function foo () { // do something on mousedown } // When needed: $("#div").bind("mousedown", foo); // When not needed: $("#div").unbind("mousedown", foo); 
+3
source

I would just stick to the if(toggle) inside the event. Why can't you do this? (the only thing I can come up with is that you would not want the event to be fired again and again, which makes sense - is this a case?)

0
source

here is a working example http://jsfiddle.net/samccone/ENzyk/

I think this is a simple and elegant solution.

0
source

All Articles