Chrome Extension

Get all child elements of parent element in javascript

var parent = document.getElementById("parent_id");
var childrens = parent.children;

If you want to get all child elements of a parent element in javascript you can use 'children' property. It will return the HTMLCollection array of all elements.


For example, if there is a div element which has id 'master' and it has child elements like paragraphs 'p' and headings 'h2' and you want to get the collection of these elements you can use below code

<h2> Success is a journey not destination </h2>
<p> If you want to be successful you have to enjoy every step that you are taking to achieve your goals and dreams. </p>
<p>There is no shortcut to success. You will have to work hard continuously to make your dreams come true.</p>

To get all child elements of master id element you can use below javascript code.

Search history ×