Message from JavaScript discussions

November 2020

— Can anyone recommend some starters on Deno? (+TS)


Is this considered good practice?

document.querySelectorAll(".class").forEach((el) => {
el.addEventListener("click", function () {
let existing = document.querySelector("#redBorder");
if (existing != null) {
existing .id = "";
} = "redBorder";

— Do you have multiple elements with the id "redBorder"?

— No, only one

— Basically its just for adding a border to one element at the time

— Any idea why document.querySelector("div a") returns an array (or at least looks like an array) of four elements (the same, just repeated four times), instead of just the first matching element?

Message permanent page

— How are you accessing the "array"?

— Let targetNode = document.querySelector("div a");

But that didn't work; I saw it had four equal elements with targetNode.length and checked the contents with targetNode[0].target.classList (from 0 to 3, obviously).

Message permanent page

— Anyway, nevemind, I took a dirtier, nondynamic approach and finally solved the issue. Hopefully it won't require being dynamic.

Message permanent page

— Yep

— Makes sense, but Record is simpler in some cases

— Watch any Ryan talk on it