Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #39703

Re: Single nodelist from multiple

Newsgroups comp.lang.javascript
Date 2021-03-18 18:50 -0700
References <wMqdnURasNrKYM79nZ2dnUU7-bnNnZ2d@westnet.com.au>
Message-ID <c355a50d-828b-49da-b9d7-124ffe4e1be2n@googlegroups.com> (permalink)
Subject Re: Single nodelist from multiple
From "Michael Haufe (TNO)" <tno@thenewobjective.com>

Show all headers | View raw


On Thursday, March 18, 2021 at 8:24:50 PM UTC-5, Andrew Poulos wrote:
> This code creates two nodelists: 
> 
> const container = document.querySelector("#test"); 
> const nodes = container.querySelectorAll("div"); 
> 
> const container2 = document.querySelector("#test2"); 
> const nodes2 = container2.querySelectorAll("div"); 
> 
> I want to join both nodelists together to form one nodelist. And I need 
> to keep them as a HTML collection rather than covert them to an array. 
> 
> Is the only approach upadting the selector to cover all the nodes I want? 


I think that's the easiest:

```
const qsa = (sel, ctx) => (ctx || document).querySelectorAll(sel)

const nodeUnion = qsa('#test div, #test2 div')
```

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Single nodelist from multiple Andrew Poulos <ap_prog@hotmail.com> - 2021-03-19 12:24 +1100
  Re: Single nodelist from multiple "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-18 18:50 -0700
    Re: Single nodelist from multiple "sc...@sauyet.com" <scott@sauyet.com> - 2021-03-19 14:59 -0700

csiph-web