document.getElementById('i1').onmouseover = ""; 

For some reason it does not work. Just does not change anything, does not write any errors. How to fix?

UPDATE1 Reason found - commands from a function cannot change the contents of a variable declared outside. But how to fix - while the question

  • and what do you want to do? try document.getElementById('i1').onmouseover = function(){ alert(this)}; - Yakovlev Andrei
  • So I need to delete the action on the contrary. As a result, onmouseover = "" should appear - kandi
  • one
    elementary: document.getElementById ('i1'). onmouseover = void 0; - Specter
  • @Spectre elementary, but does not work - kandi
  • 2
    @danpetruk, the code you offer to me displays 2! :) - Yakovlev Andrei

2 answers 2


If jQuery is used, then I would try this:

 $('#i1').attr('onmouseover', null); 

    I would try to change through .attr ("onmouseover", "") , then do something like .unbind ("mouseenter") , and then attach a new event through .on ("mouseenter")

    • The author uses pure JS - Yakovlev Andrey
    • four
      a generation that grew up on frameworks, not knowing native methods. - nolka