D
Deno

help

Using querySelector on Node

Aabi3/30/2023
I am doing something like:
const nodeList: NodeList = document.querySelectorAll(".foo");
const nodes = [...nodeList];
const result = nodes.map((n: Node) => n.querySelector("span"));
const nodeList: NodeList = document.querySelectorAll(".foo");
const nodes = [...nodeList];
const result = nodes.map((n: Node) => n.querySelector("span"));
The above will not work because querySelector is not from Node, but rather Element. Is there any good way to do this without manually tossing around Nodes? Btw, my example is contrived, the real world use case is different. I really can't do it with just one querySelectorAll call in my case.
ABTAndreu Botella (they/them)3/30/2023
even though the returned type is NodeList, only elements can match a (non-pseudo-element) selector and I don't think querySelector(All) works with pseudo-element selectors
Aabi3/30/2023
So I could just cast it?
ABTAndreu Botella (they/them)3/30/2023
yeah

Looking for more? Join the community!

Recommended Posts
Simpler way to read a file relative to current module?So I wrote a little helper function for reading the text content of a file relative to the current merror: BadResource: Bad resource IDI'm writing tests for https://github.com/deno-libs/tinyhttp/pull/9. ```js import { describe, expectRecent deployment not working?Hi there I have an api that was working just fine not sure what happen but new deployments are not wHow do you get the path to a file relative to the module which is referencing it?```ts const GET_PROGRAM_QUERY = Deno.readFileSync("./GetProgram.gql"); ``` GetProgram.gql is a fileInvestigating memory leak after adding new app dependencyHi, I added an OpenTelemetry metrics reporting loop to a Deno program and found that Deno began leakVScode deno lint blew up again after update.It seems every time there's an extension update VScode lint blows up and will stop recognizing top limport cache not workingI can't install cache of my http imports:Why isn't this error caught?Basic code example: ``` try { Deno.remove("fakefile"); } catch (err) { console.log("File doesn'tUsing dynamic import with npm compatibility gives intermittent error "__DENO_NODE_GLOBAL_THIS_167935This is pretty hard to google because the number at the end of the error changes everytime it happenGraphql codegendoes anyone have a solution to generate the sdk using graphq-request with Deno?Deno Third Party Modules Web HooksIs there a way to see the webhook payload URL a package you have published is listening for?Does Deno Deploy support location based analytics?The free version does not seem to support it. Does the paid version support it?