document.write has been used to write a text to our page. However, we can also write some HTML script using it. However, it is not advisable to write contents to webpage using document.write() because it deletes every other thing on page.
So, we write to particular part of the document using DOM. We directly pick up the div whose contents need to be changed and change it according to our wish. Here is an example :-
The method getElementById selects the Id searched for and return the selected object