Prepare for Angular Interviews with real-life questions. Utilize quizzes and examples to deepen understanding and enhance your skills. Gear up to ace your interview!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How do you create a new DOM element in JavaScript?

  1. Use document.createElement()

  2. Use document.newElement()

  3. Use document.makeElement()

  4. Use document.addElement()

The correct answer is: Use document.createElement()

To create a new DOM element in JavaScript, the method document.createElement() is used. This method is part of the Document Object Model (DOM) API and enables developers to dynamically generate elements within the page. When called, it takes a string parameter that specifies the type of element to create, such as 'div', 'span', 'p', and so forth. Once the element is created, it can be manipulated by setting properties, adding classes, or appending it to the document tree using methods such as appendChild() or insertBefore(). The other choices provided do not represent valid methods within the DOM API for creating elements. They do not exist in JavaScript, making them unsuitable for use in creating new DOM elements. Therefore, document.createElement() stands out as the correct and recognized approach for this task.