samedi 31 octobre 2020

if statement only affects the last image, how can it affect all?

I'm new to Javascript and our teacher wants us to use Javascript only, so even links etc. have to be created in there.

I made a link with the id 'mine':

  var linkMyCDS = document.createElement("a");
  linkMyCDS.className = "link";
  linkMyCDS.id = "mine";
  linkMyCDS.innerText = "my cds";
  headerContainer.append(linkMyCDS);

and I have a dataset where 'oneAlbum' represents each cd in the dataset. There is a part where I ask for each cd if it's 'in my posession' -> true or false.

Now I want to change the opacity of the images that are 'not in my posession' to 0.5. The problem is that it only changes the opacity of the last album in my array of albums.

  window.onclick = function(event){
    if(!event.target.matches('mine')){
      if(oneAlbum.in_my_possesion === false){
        albumCover.style.opacity = 0.5;
      }
    }
  }
}

I tried putting it in a for loop before, but it didn't change the outcome. I struggle a lot with for loops though.

Aucun commentaire:

Enregistrer un commentaire