Urgent.News

What's breaking now, across thousands of outlets.

Tech

Day 16: Learning JavaScript DOM Manipulation — Create, Change & Delete Elements

My webdevelopment learning journey continues Today I learned about JavaScript DOM manipulation and how to create, modify, and delete HTML elements dynamically using JavaScript. 1. document.getElementById() Used to select an HTML element using its unique ID. let heading = document.getElementById("title"); 2. document.createElement() Used to create a new HTML element. let newElement =…

On the sixteenth day of my web development learning journey, I delved into the intricacies of JavaScript DOM manipulation. This technique allows me to dynamically create, modify, and delete HTML elements directly within a webpage.

First, I discovered the `document.getElementById()` method, which enables me to select an HTML element based on its unique ID. For instance, `let heading = document.getElementById('title');` allows me to target an element labeled 'title'.

Next, I learned about `document.createElement()`, a powerful tool for generating new HTML elements on-the-fly. Using this method, I created a new paragraph element with `let newElement = document.createElement('p');`. I then populated this new element with content, assigning it the text "Hello JavaScript!" via the `.textContent` property.

To integrate the newly created element into the webpage, I employed the `appendChild()` method. By executing `document.body.appendChild(newElement);`, I appended the fresh paragraph to the body of the document, making it visible to users.

Modifying existing elements was another key focus. To change the text content of an element, I utilized the same `getElementById()` technique, followed by assigning a new string to the `.textContent` property. For example, `document.getElementById('title').textContent = 'Welcome!';` transformed the heading text from "title" to "Welcome!".

Changing images dynamically was also demonstrated. By targeting an `img` element with `document.getElementById('myImage')`, I could modify its `src` attribute, loading a different image. In this case, `document.getElementById('myImage').src = 'new-image.jpg';` replaced the existing image with "new-image.jpg".

Adjusting the appearance of elements was achieved through altering their styles. Using `document.getElementById('title')`, I accessed the element's style object and changed its color property. `document.getElementById('title').style.color = 'blue';` set the heading text to blue.

However, sometimes it's necessary to remove elements from the page. The `remove()` method proved invaluable for this task. By invoking `document.getElementById('title').remove();`, I eliminated the element labeled 'title' from the webpage.

Finally, I explored the `onclick` event, which allows executing JavaScript code in response to a user clicking an element. For instance, I defined a function `changeText()` that updates the heading text and then assigned it to the element's `onclick` attribute: `document.getElementById('title').onclick = changeText;`. This means that whenever the heading is clicked, the text will change to "Text Changed!".

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Word-by-word captions with Python and ffmpeg, no CapCut watermark

Short-form video lives or dies on captions. CapCut and a dozen web tools will do the "word lights up as you say it" style for you, usually with a watermark or a free-minute limit.

  • Python script creates synchronized captions offline
  • Uses whisper with wordtimestamps for word boundaries
  • ffmpeg integrates captions without watermark

IDCF Cloud: Ransomware Disrupts Four Eastern Japan Zones; Customers Advised to Rebuild from Backups

1. Basic Information Report Title : [Third Report] Service Disruption Caused by Unauthorized Access to Part of Our Systems Source : IDC Frontier Date : 2026-10-08 Original Source : IDC Frontier…

  • Ransomware attack disrupts IDCF Cloud's Eastern Japan Region 1 on October 7, 2026
  • Four zones affected, 495 corporate and municipal clients impacted
  • Customers advised to rebuild systems from personal backups

Detection content as code: reviewing a change the way you review software

Detection content as code: reviewing a change the way you review software The problem with editing rules in a console Detection rules written directly in a security platform have no review, no…

  • Detection rules should be treated as code with review, version control, and testing.
  • Store rules in plain text format within a repository for portability.

Why Your Static Site’s lastmod Is a Lie (And How CI/CD Shallow Clones Secretly Hurt Your SEO)

If you build static websites, documentation hubs, or content platforms using Next.js, Astro, or 11ty, there is a very high probability that your sitemap.xml is quietly lying to Googlebot every single…

  • CI/CD shallow clones timestamp all files with current time, inflating last modified dates.
  • Search engines penalize sites with false timestamps, wasting crawl budget and slowing indexing.

Cross-Chain Bridge Risk Assessment: Deribit

Cross-Chain Bridge Risk Assessment: Deribit Target Protocol : Deribit (TVL: $3898.1M) Cross‑Chain Bridge Risk Assessment – Deribit TVL: ≈ $3.9 B (Ethereum + L2) Date: 9 Oct 2026 Prepared by: Senior…

More from Friday 9 October →