Get index of a div with equal classes using mouseover () Jquery

1

I have several divs with the same class and need a function that, when I hover the mouse in any of them, with mouseover() take the index of it

    
asked by anonymous 16.01.2017 / 17:32

1 answer

3

When it says position eq() would be the index of the element?

If it is, you can use .index()

$(element).mouseover(function(){
    alert($(this).index());
});

I've created a small example, if so:

$(function(){
    $("div").mouseover(function(e){
       console.log($(this).index());
    });
});
div {
    width: 60px;
    height: 60px;
    margin: 10px;
    float: left;
    border: 2px solid blue;
}
<script src="https://code.jquery.com/jquery-1.10.2.js"></script><div></div><div></div><div></div><div></div><div></div><div></div>

link

    
16.01.2017 / 17:40