We use this JavaScript method to create a new HTML element:

document.createElement('tagName')

Example: Create a New Paragraph and Add It to the Page

// Step 1: Create the paragraph element
const newParagraph = document.createElement('p');

// Step 2: Add text inside the paragraph
newParagraph.textContent = 'This is a new paragraph added by JavaScript.';

// Step 3: Add the paragraph to the page inside the body
document.body.appendChild(newParagraph);

Step-by-Step Summary

Step What to do
1 Use document.createElement('tagName') to make a new element.
2 Add content or attributes (text, id, class).
3 Attach the element to the page with .appendChild() or .insertBefore().

Task -

Final Hard Task

🧠 innerText vs innerHTML vs textContent

1. innerText