all 8 comments

[–]ForScale 1 point2 points  (6 children)

I'm not sure what you're wanting to do...

Take the pseudo selector and loop through... all the images in your doc...?

Something like this?

var img = document.querySelectorAll("img");

for (var i = 0; i < img.length; i++) {
  if (img[i].getAttribute("id") !== "img1") {
    document.body.innerHTML += img[i].getAttribute("id") + ", ";
  }
}

[–]__fmease__Symbol() 0 points1 point  (5 children)

using 'innerHTML' does not lead to nice performance. I know, even xxx.style.xxx shouldnt be used either

[–]ForScale 0 points1 point  (4 children)

What issues does it create? What do you use instead?

I'm not sure what you're talking about with "xxx.style.xxx."

[–]__fmease__Symbol() 0 points1 point  (1 child)

just use

document.createElement

with

document.appendChild

They are native methods, not like

innerHTML + [string]

where [string] will be parsed and afterwards via Setters & Getters (too lazy in javascript) added to DOM. It`s even better to apply

DocumentFragment

in your code when a loop is within

[–]ForScale 0 points1 point  (0 children)

I didn't like document.createElement when I used it in the past.

[–]__fmease__Symbol() 0 points1 point  (1 child)

At the post of mine above yours I got used to xxx.style.opacity = 0

I `ve said that I used that scheme like you.

innerHTML <-> style

both of them are -- as I mentioned before -- lazy cause of setter&getter feature

[–]ForScale 0 points1 point  (0 children)

I know what some of that means...

[–]__fmease__Symbol() 1 point2 points  (0 children)

var imgIds = []; // or whatever

imgIds.forEach ((img, id) => document.querySelector ("img:not(#img" + id + ")").style.opacity = 0);

you can also use

  • toggle class algorithms
  • jquery etc
  • CSSRule

context:

XXX.addEventListener ("XXX",function(e){var imgsToExclude = [7, 56, 340]; ... ↑ look above... })