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
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
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