Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    JSJavaScript

    Getting started

    • What is JavaScript?
    • Variables: let, const and var
    • Data types
    • Type conversion

    Operators and strings

    • Arithmetic and assignment
    • Comparison and logic
    • Strings and template literals
    • String methods
    • Numbers and Math

    Control flow

    • Conditions: if and else
    • switch and the ternary operator
    • Loops: for and while
    • Challenge: FizzBuzz

    Functions

    • Functions
    • Arrow functions
    • Parameters: default, rest and spread
    • Scope and closures
    • Callbacks and higher-order functions

    Arrays

    • Array basics
    • map, filter and find
    • reduce and sorting
    • Destructuring

    Objects

    • Object basics
    • Copies and references
    • Methods and this
    • JSON and optional chaining

    Classes and OOP

    • Classes
    • Inheritance

    JavaScript in the page

    • Controlling the page (DOM)
    • Creating elements
    • Events
    • Forms and validation
    • Saving in the browser (localStorage)

    Errors and async

    • Handling errors: try and catch
    • Timers and the event loop
    • Promises
    • async and await
    • Fetching data from an API

    Practical tools and techniques

    • Searching with regular expressions
    • Cancellation and stale results
    • Testing and debugging JavaScript

    Modern JavaScript and a project

    • Map and Set
    • Dates and localised formatting
    • Modules: import and export
    • Project: a complete to-do app
    JavaScript

    JavaScript in the page · Lesson 29 of 45

    Controlling the page (DOM)

    Find an element on the page and change its text and style.

    9 minutes2 games

    The browser turns HTML into a tree of objects called the DOM (Document Object Model). Every tag becomes a node in the tree, and JavaScript can read and change any of it, updating the page instantly.

    • document
      • html
        • head
          • title
        • body
          • h1#title
          • ul.menu
            • li
            • li
          • button

    The DOM of a simple page.

    ToUse

    select the first match

    document.querySelector("#title")

    select every match

    document.querySelectorAll(".item")

    change text

    el.textContent = "..."

    change style

    el.style.color = "red"

    add/remove a class

    el.classList.add("active") / .remove / .toggle

    read/set an attribute

    el.getAttribute("href") / el.setAttribute(...)

    HTML
    <style>.done { text-decoration: line-through; color: gray; }</style>
    <h2 id="title">Hello</h2>
    <ul>
      <li class="task">Learn HTML</li>
      <li class="task">Learn CSS</li>
      <li class="task">Learn JS</li>
    </ul>
    
    <script>
      const title = document.querySelector("#title")
      title.textContent = "My tasks"
      title.style.color = "teal"
    
      const tasks = document.querySelectorAll(".task")
      tasks[0].classList.add("done")
      tasks[1].classList.add("done")
      console.log(tasks.length, "tasks")
    </script>

    #title is an id, .task a class, ul li an li inside a ul: exactly CSS selectors.

    Important

    Prefer classList over style: keep the looks in CSS and let JavaScript just switch classes. Easier to maintain and cleaner.

    Interview question

    What's the difference between textContent and innerHTML, and why can innerHTML be dangerous?

    Complete the code

    Select the element whose id is price.

    const el = document.("")

    Quick question

    You want to show and hide something on each click. Which tool fits best?

    Learn more from

    • javascript.info: DOM treejavascript.info
    • javascript.info: Searching: getElement*, querySelector*javascript.info
    • MDN: Introduction to the DOMdeveloper.mozilla.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousInheritanceNextCreating elements
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.