As my title shows I've problem using the off-method in JQuery combined with mouseover/mouseout.
My HTML-code(the relevant part):
<h3>Hover</h3>
<p id="hover">Move the mouse pointer over this paragraph.</p>
<button id="off">Press the button</button>
My JQuery-code(the relevant part):
$(document).ready(function(){
$("#hover").mouseover(function(){
$("#hover").css("background-color", "green");
});
$("#hover").mouseout(function(){
$("#hover").css("background-color", "lightblue");
});
$("#off").click(function(){
$("#hover").off("click");
});
});
The "hover-part" works fine. But when i press the button, which supposed to stop the mouseover and mouseout-methods to stop, it doesn't.
You should use jQuery's
unbind
, to set off the event handlers like this:Hope this helps!