/html-dom /Basic
GitHub 5008★

Select the children of an element

Get the children nodes of the ele element:

const childNodes = ele.childNodes;

By looping over the chidren, you can get the first or last child:

const first = childNodes[0];
const last = childNodes[childNodes.length - 1];

There are properties to access the first and last child directly:

const first = ele.firstChild;
const last = ele.lastChild;

See also

Follow me on and to get more useful contents.