Javascript DOM Interview Question-1

Shivam Gupta
2 min readSep 11, 2019

--

You have given Html element structure -

Html Page

Now you need to insert data to every div using Javascript!

First we need to get length of nested HTML elements

Getting Total nested elements

Now loop over children <div> and append <p> hey </p> element

Write hey to every div

Output:

Using js append children to div

Now HTML structure look likes —

Newly created DOM

Execute this code here —

If you like this post please give a clap and follow. Write in the comment section for any question or suggestion.

--

--

Shivam Gupta
Shivam Gupta

Written by Shivam Gupta

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK...Love to write cool stuff

No responses yet