TGViewer
Web Development - HTML, CSS & JavaScript Web Development - HTML, CSS & JavaScript @javascript_courses ยท 55.7K subscribers
Post #3180 4.44K
โœ… JavaScript DOM Manipulation, Events & Forms ๐Ÿ–ฑ๏ธ๐Ÿ“„

Learning how to interact with the webpage is essential in frontend development. Here's how the DOM, events, and forms work in JavaScript:

1๏ธโƒฃ What is the DOM?
DOM (Document Object Model) is the structure of your web page. JavaScript can access and change content, styles, or elements using the DOM.
<p id="message">Hello!</p>

```js
let msg = document.getElementById("message");
msg.textContent = "Welcome!";

โ–ถ๏ธ This selects the paragraph and changes its text to โ€œWelcome!โ€

2๏ธโƒฃ Selecting Elements

js
document.querySelector("h1"); // Selects first <h1>
document.querySelectorAll("li"); // Selects all <li> elements

3๏ธโƒฃ Changing Content or Style

js
let btn = document.getElementById("btn");
btn.style.color = "red";
btn.textContent = "Clicked!";

4๏ธโƒฃ Events in JavaScript  
You can listen for user actions like clicks or key presses.

html
<button id="btn">Click Me</button>

```
```js
document.getElementById("btn").addEventListener("click", function() {
alert("Button clicked!");
});

โ–ถ๏ธ This shows an alert when the button is clicked.

5๏ธโƒฃ Handling Forms

html
<form id="myForm">
<input type="text" id="name" />
<button type="submit">Submit</button>
</form>

```
```js
document.getElementById("myForm").addEventListener("submit", function(e) {
e.preventDefault(); // Prevents page reload
let name = document.getElementById("name").value;
console.log("Hello, " + name);
});

`
โ–ถ๏ธ This handles form submission and prints the entered name in the console without refreshing the page.

๐Ÿ’ก Practice Ideas:
โ€ข Make a button that toggles dark mode
โ€ข Build a form that displays entered data below it
โ€ข Count key presses in a textbox

๐Ÿ’ฌ Tap โค๏ธ for more!
  • โค 7
More from @javascript_courses
  1. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
  2. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  3. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  4. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
  5. Oct 4, 2026DSA Handwritten Notes
  6. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these stโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’