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

Asked

Viewed 259 times

1

I have several divs with the same class and need a function that when I pass the mouse on any of them, with mouseover() get her index

  • It helps if you show the code...

  • Thank you for your attention, I have already received an answer

  • Mark the answer then. Don’t leave the question open.

  • 1

    The guy who answered that did magic, I keep thinking that this question is low quality.

1 answer

3


When you say position eq() would be the index of the element?

If so, you can use .index()

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

I created a little example, if that’s it:

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

https://jsfiddle.net/leonardorodrigues/0qon0aa8/

  • Exactly Leonardo, that’s what I needed! Thank you very much!!

  • @Gustavosantana, mark the answers that helped. Do not abandon the questions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.