How to remove the onmouseout event after having assigned a function?

I have a problem, I'm assigning a function to the onmouseout event, but after running the event, I need to remove it. would greatly appreciate your help.

Answers


This depends on your code, if you did this with d3, then you can say

inside your onmouseout event-function:

element.on("mouseout",func);

function func(){
    /*do your stuff*/
    element.on("mouseout",null);
}

If you bound the event via an event-attribute like <div onmouseout="..." > then you have to refactor this. In this case, simply use the d3 on() function to bind the event.

If you want to bind multiple handlers to the same event, you can use namespacing: By appending .name to the event, you can address them more specifically.


I'm assuming you added your event listener with d3's on event. their docs for removing an event is such:

If an event listener was already registered for the same type on the selected element, the existing listener is removed before the new listener is added. To register multiple listeners for the same event type, the type may be followed by an optional namespace, such as "click.foo" and "click.bar". To remove a listener, pass null as the listener.

I can't correct your code, because you didn't add any.


Another way is to use jQuery:

$(element).bind("mouseout", myFunction);
$(element).unbind("mouseout");

jQuery unbind jQuery bind

You can also use an optional namespace in the first parameter like:

"mouseout.myNamespace"

With this namespace you can bind/unbind multiple events of the same kind.

Another thing that maybe is interesting to you: jQuery stopPropagation


Need Your Help

Duplicate attributes generated in WSDL using @XmlMimeType() on CXF, Why?

wsdl cxf mtom

I've developed a CXF web services with MTOM enabled. I've added an annotation to my DTO to tell JAXB the field candidate for MTOM optimization:

Magento - Event/observer code to associate configurable product image to its children, is not working

php image magento events product

I am moving our company site to Magento and have run into a snag with product images. We have 15k products, 80% of which are simple products with a configurable parent. We paid for a cart transfer,...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.