开发者

Jquery help with mouse events, events not unbinding

Any ideas why this doesn't work, or how to make it work? I want to remove the "onmouseover" and "onmouseout" events so they are basically disabled and at the same time change the background color. Then when the user clicks on another element I want to reassign the mouse events back to the element. Right now the onmouse events don't get disa开发者_开发百科bled at all, the background doesn't change, etc.

Here's how I call the function:

Here's the function: $(document).ready(function(){

$(".maximize").toggle(

   function(){ 

    $("#property_bg").unbind("onmouseover");
    $("#property_bg").unbind("onmouseout"); 
    $("#property_bg").toggleClass("body_bgcolor");
   }, 

       function() { 

        $("#property_bg").bind("onmouseover", function() {        
                              swap_class("property_bg","body_bgcolor")} );      

   });

});

Thanks for the help.


Remove the "on" from the event names. Then it'll work.


on your events, take out the 'on'... just mouseover or mouseout...


I found out the real problem in the following two threads for anyone who comes along with a similar problem I will add them here:

How do I unbind "hover" in jQuery?

Why this unbind doesn't work?

The problem was solved by not hard coding the mouse events in the HTML, but rather binding them in the document.ready 1st. In order to "unbind" and event, the event has to be "binded" by jquery.

Also, "mouseover" didn't work for some reason I couldn't figure out, but when I put "mouseenter" and "mouseleave" as suggested in one of the posts above it worked. I've never heard of "mouseenter" or "mouseleave", but ... it works now.

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜