Pirune
Pirune

Reputation: 195

How can I get nth row of div after mouse over this

$(document).ready(function() {
    $('div').on('mouseover', function() {
        alert($('div:eq(' + this + ')'));
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>aaaaa</div>
<div>aaaaa</div>
<div>aaaaa</div>

I want to get div nth-child of row after mouse move to over this div

e.g

<div>aaaa</div>
<div>aaaa</div>
<div>aaaa</div>

If mouse over div nth-child(2) -> alert 2, over(3) -> alert 3

Upvotes: 0

Views: 42

Answers (3)

Rajon Tanducar
Rajon Tanducar

Reputation: 378

You can do something like this,

 $("div:nth-child(2)").click(function(){
 $(this).hide();

});

Upvotes: 0

Thum Choon Tat
Thum Choon Tat

Reputation: 3090

Iterate over every element you get and add hover event on it

$('div').each(function(index,elem){
    $(elem).hover(function(){
        alert(index+1);
    });
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>aaaa</div>
<div>aaaa</div>
<div>aaaa</div>

Upvotes: 2

Jay Shankar Gupta
Jay Shankar Gupta

Reputation: 6088

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#1").mouseover(function(){
        alert("1");
    });
    $("#2").mouseover(function(){
        alert("2");
    });
    $("#3").mouseover(function(){
        alert("3");
    });
});
</script>
</head>
<body>
<div id="1">aaaa</div>
<div id="2">aaaa</div>
<div id="3">aaaa</div>

</body>
</html>

may this you want

Upvotes: 0

Related Questions