<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
path1tent="
width
=
device
-width,
initial-scale
=
1
.0">
</
script
>
<
script
src
=
</
script
>
</
head
>
<
body
>
<
div
>
<
h5
>1. This is odd</
h5
>
<
h5
>2. This is even</
h5
>
<
h5
>3. This is odd</
h5
>
<
h5
>4. This is even</
h5
>
<
h5
>5. This is odd</
h5
>
</
div
>
<
script
>
// Filtering odd children
var even = d3.selectAll("h5")
.select(function (d, i) {
return i & 1 ? this : null
});
// Filtering even children
var odd = d3.selectAll("h5")
.select(function (d, i) {
return i & 1 ? null : this
});
// Merging both selections
const merged = odd.merge(even).nodes();
even = even.nodes();
odd = odd.nodes();
console.log("Odd selection: ")
odd.forEach((e) => {
console.log(e.textContent);
});
console.log("Even selection: ")
even.forEach((e) => {
console.log(e.textContent);
});
// Printing text content
console.log(
"Collection after merging odd and even is:")
merged.forEach((e) => {
console.log(e.textContent);
});
</
script
>
</
body
>
</
html
>