webtech2

🌐 WebTech2 – Project Overview

Access the project here: www.d4mr0.tech

Web 1240 - https://n16htb0t.github.io/WEB_1240/

REACT: https://github.com/n16htb0t/webtech2/blob/main/ReactPart/React%20Part%201%2022390c2fa21b8088ac9cd6f612c3ac32.md

Drive: https://drive.google.com/drive/u/2/folders/15j1Es0mq-1nEVQbMYGq2s1oD8vQGeaYx

```js for react project 4

npm install .

npm install styled-components

```

Helpful Websites

DOM Cheatsheet

A quick reference for working with the Document Object Model (DOM) in JavaScript.

🧱 DOM Selection Methods

Method Description Example
getElementById() Selects element by ID document.getElementById("header")
getElementsByClassName() Selects elements by class name (HTMLCollection) document.getElementsByClassName("item")
getElementsByTagName() Selects elements by tag name (HTMLCollection) document.getElementsByTagName("li")
querySelector() Selects first matching element (CSS-style) document.querySelector(".btn")
querySelectorAll() Selects all matching elements (NodeList) document.querySelectorAll("ul li")

✏️ DOM Manipulation

Property/Method Description Example
element.textContent Gets or sets text el.textContent = "Hello"
element.innerHTML Gets or sets HTML el.innerHTML = "<strong>Hi</strong>"
element.setAttribute() Sets attribute el.setAttribute("class", "active")
element.getAttribute() Gets attribute el.getAttribute("href")
element.removeAttribute() Removes attribute el.removeAttribute("disabled")
element.classList.add() Adds class el.classList.add("visible")
element.classList.remove() Removes class el.classList.remove("hidden")
element.classList.toggle() Toggles class el.classList.toggle("dark-mode")

⚙️ DOM Events

Method/Property Description Example
addEventListener() Adds event listener btn.addEventListener("click", fn)
removeEventListener() Removes event listener btn.removeEventListener("click", fn)
event.target Refers to the element that triggered event e.target.style.color = "red"

🌱 Creating & Inserting Elements

Method/Property Description Example
document.createElement() Creates new element let p = document.createElement("p")
element.appendChild() Appends as last child parent.appendChild(p)
element.prepend() Inserts as first child parent.prepend(p)
element.append() Appends one or more nodes el.append("Hello", span)
element.insertBefore() Inserts before reference node parent.insertBefore(newEl, refEl)
element.remove() Removes element el.remove()

💡 Other Useful DOM Tricks

Concept Example
Loop through NodeList document.querySelectorAll(".item").forEach(el => { ... })
Convert HTMLCollection to Array Array.from(document.getElementsByClassName("item"))
Check if class exists el.classList.contains("active")
Modify style el.style.color = "blue"

📁 Project Structure (Click to view files)

📂 Quizzes

📂 JS/

📂 lesson 2/

📂 lesson 3/

📂 lesson 4/

📂 lesson 5/

📂 lesson 6/

License

This cheatsheet is free to use and modify. Feel free to contribute!