-1

On hover I want to call a function. If the element has the class "disabled_btn" it shall be supressed. Why is mode code not working? jsfiddle

html

<button id="btn" > hover here</button>

JS

$('#btn:not(.disabled-btn)').on('hover', function(){ 
                alert('click');
            });
vuvu
  • 4,886
  • 12
  • 50
  • 73

4 Answers4

3

Try mouseover instead of hover:

$('#btn:not(.disabled-btn)').on(' mouseover', function () {   
    alert('click');
});

Demo: http://jsfiddle.net/qa7co8y4/2/

K K
  • 17,794
  • 4
  • 30
  • 39
  • 2
    After reading the question again, I think this works better for vuvus needs. `hover()` will trigger the event again on `mouseleave`, and that's not what he wants. Got confused by what he had already tried. I think this is the correct answer. – balzafin Nov 21 '14 at 15:18
1

You should use .hover() instead of on("hover"). Like this:

$('#btn:not(.disabled-btn)').hover(function() {
    alert('click');
});

Fiddle: http://jsfiddle.net/qa7co8y4/3/

balzafin
  • 1,416
  • 1
  • 17
  • 28
1

There is nothing like hover on JS you need to use mouseenter or mouseover instead.

$('#btn:not(.disabled-btn)').on(' mouseenter', function () {   
    alert('click');
});

or

$('#btn:not(.disabled-btn)').on(' mouseover', function () {   
    alert('click');
});
LJ Wadowski
  • 6,424
  • 11
  • 43
  • 76
1

Ive update your code for you see Updated Code

$('#btn:not(.disabled-btn)').hover(function(){ 
                    alert('click');
                });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btn" class=""> hover here</button>
Tony_89
  • 797
  • 11
  • 39