0

I am using a slick carousel and I wanted the non-active slides to be at opacity .4.... So I created an array of variables (the variables are referencing classes of the slides) and a for loop to iterate through the variables for a .click() jQuery function on click of X class, .css opacity .4 on all others. On the click only one class (one other slide image) would fade, so I looped through the array and console.logged both the array[i] and the array. To my surprise when console.logging array[i] it logged the html with the class and inline styling changes made. When I console logged the array it logged [div.test__image.explosiveness] (The very last index in the array). What is wrong with my loop/how can I target all of the indexes for a css change? I am using PUG for the HTML and JS/ jQuery. Thank you for your help and suggestions in advance!

.carousel
.carousel__slide
    .test
        .test__image.explosiveness
        p Explosiveness
.carousel__slide
    .test
        .test__image.agility
        p Agility
.carousel__slide
    .test
        .test__image.flexibility
        p Flexibility
.carousel__slide
    .test
        .test__image.balance
        p Balance
.carousel__slide
    .test
        .test__image.footwork
        p Footwork
.carousel__slide
    .test
        .test__image
        p Explosiveness
// carousel fades
var agility = document.getElementsByClassName('agility'),
    explosiveness = document.getElementsByClassName('explosiveness'),
    flexibility = document.getElementsByClassName('flexibility'),
    balance = document.getElementsByClassName('balance'),
    footwork = document.getElementsByClassName('footwork');

var nonFootwork = (agility, balance, flexibility, explosiveness);

$('.footwork').click(function(){
    var len = nonFootwork.length;
    for(var i = 0; i < len; i++){
        $(nonFootwork[i]).css('opacity', '.4');
        console.log(nonFootwork[i]);
        console.log(nonFootwork);
        $('.footwork').css('opacity', '1');
    }
});
1
  • var nonFootwork = (agility, balance, flexibility, explosiveness); is equivalent to var nonFootwork = explosiveness; Commented Jul 18, 2017 at 18:15

1 Answer 1

2

You should declare an array using brackets instead of parenthesis:

var nonFootwork = [agility, balance, flexibility, explosiveness];
Sign up to request clarification or add additional context in comments.

1 Comment

Hahaha... Wow, I feel retarded. My bad. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.