Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. JavaScript Course

Lesson 9 of 55 · javascript

Manipulating the DOM – Creation, Insertion & Removal

Duration: 12 mins

Creating elements:

const div = document.createElement('div');

Setting attributes & content:

div.id = 'myDiv';
 div.className = 'card';
 div.textContent = 'Hello';

Appending / inserting:

document.body.appendChild(div);
// insert before an existing node
parent.insertBefore(newNode, referenceNode);

Removing:

div.remove(); // modern
parent.removeChild(div); // legacy
Previous: The Document Object Model (DOM)Next: Event Handling – Adding & Removing Listeners