0

Hey guys simple problem I think. Have 3 divs, trying to remove and add back OnMouseOver for "body_flex" div. What am I missing here?

function contact_open() {
        $("#body_flex_wrapper_id").removeAttr('onmouseover')
}
function contact_close() {
        $("#body_flex_wrapper_id").attr('onmouseover');     
}

2 Answers2

1

you can toggle that using attr and removeAttr

$(function(){
  $("#btnToggle").click(function(){
     if ($("#div1").attr("onmouseover")){
          $("#div1").removeAttr("onmouseover");
     }
     else{
        $("#div1").attr("onmouseover", "overx();");
     }
  })

})

function overx(e){
   console.log($("#div1").text());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<button id="btnToggle">Toggle</button>

<div id="div1" onmouseover="overx();">
  <span>sample div</span>
</div>
Jeric Cruz
  • 1,769
  • 11
  • 26
  • please mark it as an answer if this answer is what you're looking for so we could have a better reference in the future. – Jeric Cruz Apr 30 '17 at 03:50
0

Try this:

function contact_open() {
    $("#body_flex_wrapper_id").removeProp('onmouseover', null);
}
function contact_close() {
        $("#body_flex_wrapper_id").prop('onmouseover', null);
}
  • Keep in mind that `.bind()` and `.unbind()` have been depreciated. Use `.on()` and .`off()` instead. http://api.jquery.com/bind/ and http://api.jquery.com/unbind/ – blackandorangecat Apr 25 '17 at 03:03
  • same for .on and .off – LeeAlexander Apr 25 '17 at 03:05
  • removeProp does its job, but prop won't bring it back. What about disabling a function? The mouseover is just on a large div that slides a menu back when user rolls over. So if we can't disable the mouseover on it, what about the function that MO is calling? – LeeAlexander Apr 25 '17 at 03:14