Creating a Repeating Statement

Asked 2 years ago, Updated 2 years ago, 45 views

$(".list a:nth-child(1)").mouseover(function(){
         $(".cursor li").hide();
         $(".cursor li:nth-child(1)").show();
       });

How can I write that nth-child(1) part to keep repeating as the number increases by 1?

javascript jquery

2022-09-22 18:52

1 Answers

Don't increase by one, just turn around. demo

$(".list a").ear(function(i) { // index obtainable
    $(this).mouseover(function () {
        $(".cursor li").eq(i);show(); // use acquired index
    }).mouseout(function () {
        $(".cursor li").hide();
    });
});

Learn about jQuery's each() method , eq() method.


2022-09-22 18:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.