PRIMO
SECOND...">

JQuery - adding a mouse event listener to a class

<div class="teamMain">
    <div class="teamScroll">
        PRIMO
    </div>

    <div class="teamScroll">
        SECONDO
    </div>

    <div class="teamScroll">
        TERZO
    </div>
</div>

And I would like to add a kind of listener (such a mouseover or mouseout) for each of this div, taking the teamScroll class as a reference.

I know that there is a delegation method, but it only works with jquery-1.4.2 (which, as I laid out time ago for another problem ) violated some functions with IE6.

Is there another way to do this without adding an N listener for the N div?

Greetings

+3
source share
3 answers

You can use a regular .hover()handler, for example:

$(".teamScroll").hover(function() {
  //mouse on the item
}, function() {
  //mouse off the item
});

, ( 2n, ), , 1.4.2 ... 1.3.2, .live() :

$(".teamScroll").live("mouseenter", function() {
  //mouse on the item
}).live("mouseleave", function() {
  //mouse off the item
});

, .live() , document... as mouseover mouseout , .

.delegate() , jQuery 1.4.4 , 1.4.2, 1.4.3/1.4.4 AJAX.

+5

Try

$('.teamScroll').bind('onmouseover', function() {
  alert('Mouseover');
});
+1
$('.teamScroll').mouseover(function(){

});
0
source

Source: https://habr.com/ru/post/1780057/


All Articles