/html-dom /Basic
GitHub 5008★

Select an element or list of elements

Select an element by given ID

<div id="hello" />;

document.getElementById('hello');

Select elements by class name

Returns the list of elements that have hello class within a given element:

ele.getElementsByClassName('hello');

Select elements by tag name

Returns the list of span inside a given element:

ele.getElementsByTagName('span');

Select elements by CSS selector

Returns the list of elements that match a given selector:

ele.querySelectorAll('div.hello');

Returns the first element that match a given selector:

ele.querySelector('div.hello');

See also

Follow me on and to get more useful contents.