0

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 disabled 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.

Ricket
  • 33,368
  • 30
  • 112
  • 143
Ronedog
  • 2,313
  • 8
  • 43
  • 85

3 Answers3

2

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

icktoofay
  • 126,289
  • 21
  • 250
  • 231
  • thanks for the reply. I removed the "on", but still not working. I should have included that this is in a dynamically created page and the code is after a $(document).ready(function(). The mouse events are hardcoded in the script and I include the jquery script after the html string is made. I don't know if that makes a difference. There are some other functions called right after these that work fine, so I at least know the toggle stuff is partly working. Do I need to include something like .live() to make this work? – Ronedog Feb 09 '10 at 05:35
  • I don't know your particular situation, but .live() binds something to the event, and if any more elements match that selector in the future, it'll start binding to those, too. Anyway, I tried your code with my suggestion, (and just a guess of what swap_class does) and it seems to be working fine, though admittedly as I said before, I don't really know what you're trying to accomplish here. – icktoofay Feb 09 '10 at 06:55
  • thanks. swap simply changes the class name. I figured out what the real problem was...my lack of knowldedge of some core functionality of bind. see my answer. Thanks again for being willing to help out. – Ronedog Feb 09 '10 at 16:27
0

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

Reigel Gallarde
  • 64,198
  • 21
  • 121
  • 139
0

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!

Community
  • 1
  • 1
Ronedog
  • 2,313
  • 8
  • 43
  • 85