DEV Community

Cover image for Preparing a React course in public - modifying the DOM with Vanilla Js
Manuel Artero Anguita 🟨
Manuel Artero Anguita 🟨

Posted on

1

Preparing a React course in public - modifying the DOM with Vanilla Js

I love Vanilla JavaScript.

It feels so pure.
Back to basics. No layers of complexity.
Just, «these functions are the browser's API; that's it, that's what you can do».

Nothing more, nothing else.


In the next exercise, my goal is for my class to understand that each framework, each library - React, Vue, Angular, Next, Nuxt - essentially wraps and adds layers to the browser's API.

Before diving into the code, I'll take a step back to review what the browser is...
Like, ok it's a program... that renders HTML, CSS, and executes JavaScript.

«Executes JavaScript» 🤔

We are going to open a blank, raw, console;

Screenshot of a blank console where we have added a heading to the empty body

(this is the code from the screenshot)

const el = document.createElement('h1')
el.textContent = 'Hello'
document.body.appendChild(el)
Enter fullscreen mode Exit fullscreen mode

First Exercise

Our starting point was a raw HTML (zero Js) rendering n <article />

       <article class="card">
          <h2>Hulk</h2>
          <img
              src="https://marvelcdb.com//bundles/cards/01050.png"
              alt="Hulk"
          />
        </article>
        ...
        <article...>
Enter fullscreen mode Exit fullscreen mode

Our goal is to create these elements dynamically using document.createElement()

➡️ this is the function we need to implement:

/**
 * @param {object} props
 * @param {{ code: string; name: string; image: string; }} props.cardInfo
 */
function Card(props) {
  const { cardInfo } = props;
  // TODO
}
Enter fullscreen mode Exit fullscreen mode

Next: solution to the Vanilla JS exercise.


Cover image created by leonardo.ai; prompt: «Renaissance-era professor in a steampunk-style starting a fight. adorned with intricate, mechanical details.»; 3D Animation-Style.

Thanks for reading 💛.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay