Web Development - HTML, CSS & JavaScript
55.4K subscribers
1.93K photos
5 videos
34 files
539 links
Learn to code and become a Web Developer with HTML, CSS, JavaScript , Reactjs, Wordpress, PHP, Mern & Nodejs knowledge

Managed by: @love_data
Download Telegram
๐—–๐—œ๐—ฆ๐—–๐—ข ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐ŸŽ“

Boost your Resume & LinkedIn Profile with valuable tech skills

Explore FREE Cisco learning resources! ๐Ÿš€

๐ŸŒ Networking Fundamentals
๐Ÿ” Cybersecurity
โ˜๏ธ Cloud & DevOps
๐Ÿ’ป IT Fundamentals

๐ŸŽฏ Perfect for Students, Freshers & Job Seekers!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/3WPl0Qg

๐Ÿ“Œ SAVE & SHARE with friends interested in Tech Careers! ๐Ÿ”ฅ
โค2
๐Ÿš€ ๐—ง๐—ข๐—ฃ ๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐——๐—˜๐—ฉ๐—ข๐—ฃ๐—ฆ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! โ˜๏ธ

๐ŸŽ“ Explore 4 FREE learning resources to build valuable DevOps skills!

โœ… Beginner-Friendly Resources
โœ… Learn at Your Own Pace
โœ… Build In-Demand Technical Skills

๐ŸŽฏ Perfect for Students, Freshers & Aspiring DevOps Engineers!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/3WKDbGO

๐Ÿ“Œ SAVE & SHARE with friends interested in DevOps careers! ๐Ÿ”ฅ
โค1
๐—ง๐—ข๐—ฃ ๐Ÿฑ ๐—™๐—ฅ๐—˜๐—˜ ๐—ฅ๐—˜๐—ฆ๐—ข๐—จ๐—ฅ๐—–๐—˜๐—ฆ ๐—ง๐—ข ๐— ๐—”๐—ฆ๐—ง๐—˜๐—ฅ ๐—ฆ๐—ค๐—Ÿ! ๐Ÿ“Š

Discover 5 FREE learning resources to make SQL easier to understand!

โœ… SQL Basics & Queries
โœ… Joins & Subqueries
โœ… GROUP BY & Window Functions
โœ… Hands-On SQL Practice
โœ… Interview Preparation

๐ŸŽฏ Perfect for Students, Freshers & Aspiring Data Analysts!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/4CoB4J2

๐Ÿ“Œ SAVE & SHARE with friends learning SQL! ๐Ÿ”ฅ
โค1
๐Ÿš€ ๐—œ๐—ป๐—ฑ๐—ถ๐—ฎ ๐—”๐—œ ๐—ข๐—ฝ๐—ฒ๐—ป | ๐—ง๐˜‚๐—ฟ๐—ป ๐˜†๐—ผ๐˜‚๐—ฟ ๐—”๐—œ ๐˜€๐—ธ๐—ถ๐—น๐—น๐˜€ ๐—ถ๐—ป๐˜๐—ผ ๐—ฎ ๐—ฐ๐—ฎ๐—ฟ๐—ฒ๐—ฒ๐—ฟ ๐—ผ๐—ฝ๐—ฝ๐—ผ๐—ฟ๐˜๐˜‚๐—ป๐—ถ๐˜๐˜†๐Ÿ˜

Internships paying up to โ‚น1 lakh/month and full-time roles offering up to โ‚น50 LPA.

๐Ÿ† โ‚น50,000 for first place ยท โ‚น1.2 lakh in total cash prizes across the top 20

๐Ÿ“… 12โ€“13 December ยท Round 1 test and interview

๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฒ๐—ฟ ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜ ๐Ÿ‘‡:-

https://pdlink.in/4APQjZN

๐Ÿ“Œ Save the dates and share this with a friend whoโ€™s building with AI.
โค3
โŒจ๏ธ JavaScript Neat Tricks you should know
โค5
๐—ง๐—ข๐—ฃ ๐Ÿฏ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—˜๐—ฅ๐—ง๐—œ๐—™๐—œ๐—–๐—”๐—ง๐—œ๐—ข๐—ก๐—ฆ ๐—œ๐—ก ๐——๐—”๐—ง๐—” ๐—ฆ๐—–๐—œ๐—˜๐—ก๐—–๐—˜ & ๐—”๐—ก๐—”๐—Ÿ๐—ฌ๐—ง๐—œ๐—–๐—ฆ! ๐Ÿ“Š

Kick-start your career in Data Science or Data Analytics

โœ… Build In-Demand Technical Skills
โœ… Strengthen Your Resume
โœ… Explore Certification Opportunities

๐ŸŽฏ Perfect for Students, Freshers & Aspiring Data Analysts!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/4g3OYGL

๐Ÿ“Œ SAVE & SHARE with your friends! ๐Ÿ”ฅ
๐ŸŸจ JAVASCRIPT LEARNING SERIES: DAY 10

๐ŸŒ DOM Manipulation in JavaScript

DOM stands for Document Object Model.

It allows JavaScript to interact with HTML elements and dynamically change the content, structure, and styling of a webpage.

For example, JavaScript can:

โ€ข Change heading text.

โ€ข Change colors and styles.

โ€ข Add or remove HTML elements.

โ€ข Respond to button clicks.

โ€ข Validate form inputs.

โ€ข Make webpages interactive.

Let's understand it step by step.

1๏ธโƒฃ What is the DOM?

When a browser loads an HTML page, it creates a tree-like structure of elements called the DOM.

Example HTML:

<!DOCTYPE html>
<html>
<body>
<h1>Hello World</h1>
<p>Welcome to JavaScript</p>
</body>
</html>


JavaScript can access and modify these elements through the DOM.

2๏ธโƒฃ Selecting HTML Elements

Before changing an element, we need to select it.

getElementById()

Selects an element using its ID.

<h1 id="title">Hello World</h1>


let heading = document.getElementById("title");

console.log(heading);


querySelector()

Selects the first element matching a CSS selector.

let heading = document.querySelector("#title");
let paragraph = document.querySelector(".description");


querySelectorAll()

Selects all elements matching a CSS selector.

let items = document.querySelectorAll("p");

console.log(items);


Other selection methods:

โ€ข getElementsByClassName(), Selects elements by class name.

โ€ข getElementsByTagName(), Selects elements by tag name.

3๏ธโƒฃ Changing Text Content

JavaScript allows us to change the text inside HTML elements.

<h1 id="heading">Old Heading</h1>


let heading = document.getElementById("heading");

heading.textContent = "Welcome to JavaScript!";


The heading will now display:

Welcome to JavaScript!

textContent vs innerHTML

โ€ข textContent changes or retrieves text.

โ€ข innerHTML reads or changes HTML markup inside an element.

Example:

document.getElementById("heading").innerHTML =
"<span>Hello JavaScript</span>";


Use innerHTML carefully with untrusted input because inserting unsafe HTML can create security vulnerabilities.

4๏ธโƒฃ Changing CSS Styles

You can dynamically change the styling of an element.

<p id="message">Hello World</p>


let message = document.getElementById("message");

message.style.color = "blue";
message.style.fontSize = "24px";
message.style.backgroundColor = "lightyellow";


The paragraph's appearance will change instantly.

5๏ธโƒฃ Adding and Removing CSS Classes

Instead of changing individual styles, you can use classList.

add()

element.classList.add("active");


remove()

element.classList.remove("active");


toggle()

Adds a class if it doesn't exist and removes it if it does.

element.classList.toggle("active");


contains()

Checks whether an element has a particular class.

console.log(element.classList.contains("active"));
6๏ธโƒฃ Handling Events

Events allow JavaScript to respond to user actions.

Common events include:

โ€ข click, When an element is clicked.

โ€ข mouseover, When the pointer moves over an element.

โ€ข mouseout, When the pointer leaves an element.

โ€ข keydown, When a keyboard key is pressed.

โ€ข submit, When a form is submitted.

โ€ข change, When an input value changes.

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


let button = document.getElementById("btn");

button.addEventListener("click", function() {
console.log("Button Clicked!");
});


Whenever the user clicks the button, the message appears in the console.

7๏ธโƒฃ Creating New HTML Elements

JavaScript can create HTML elements dynamically.

let paragraph = document.createElement("p");

paragraph.textContent = "This is a new paragraph.";

document.body.appendChild(paragraph);


Here:

โ€ข createElement() creates a new element.

โ€ข textContent adds its text.

โ€ข appendChild() inserts it into the page.

8๏ธโƒฃ Removing HTML Elements

You can remove elements using remove().

<p id="text">Remove this paragraph</p>


let paragraph = document.getElementById("text");

paragraph.remove();


The paragraph will be removed from the webpage.

9๏ธโƒฃ Working with Input Fields

JavaScript can read values entered by users.

<input type="text" id="username" placeholder="Enter your name">

<button id="submit">Submit</button>


let button = document.getElementById("submit");

button.addEventListener("click", function() {
let name = document.getElementById("username").value;

console.log("Welcome " + name);
});


The .value property retrieves the current value of an input field.

๐Ÿ”Ÿ DOM Traversal

DOM traversal means moving between related HTML elements.

Some useful properties:

โ€ข parentElement, Gets the parent element.

โ€ข children, Gets the child elements.

โ€ข firstElementChild, Gets the first child element.

โ€ข lastElementChild, Gets the last child element.

โ€ข nextElementSibling, Gets the next sibling.

โ€ข previousElementSibling, Gets the previous sibling.

<div id="parent">
<p>First</p>
<p>Second</p>
</div>


let parent = document.getElementById("parent");

console.log(parent.children);
console.log(parent.firstElementChild);


1๏ธโƒฃ1๏ธโƒฃ Event Object

When an event occurs, JavaScript provides an event object containing information about that event.

button.addEventListener("click", function(event) {
console.log(event.type);
console.log(event.target);
});


Output:

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


Some useful event properties:

โ€ข event.type, Type of event.

โ€ข event.target, Element that triggered the event.

โ€ข event.preventDefault(), Prevents the browser's default action.

1๏ธโƒฃ2๏ธโƒฃ Event Bubbling

Event bubbling means an event triggered on a child element can propagate upward to its parent elements.

For example:

<div id="parent">
<button id="child">Click Me</button>
</div>
document.getElementById("parent")
.addEventListener("click", function() {
console.log("Parent Clicked");
});

document.getElementById("child")
.addEventListener("click", function() {
console.log("Child Clicked");
});


Clicking the button produces:

Child Clicked
Parent Clicked


This happens because the event bubbles from the child to the parent.

๐Ÿ’ป Real-World Example: Interactive Counter

Let's create a simple counter using DOM manipulation.

<h2 id="count">0</h2>

<button id="increase">Increase</button>
<button id="decrease">Decrease</button>


```javascript
let count = 0;

let display = document.getElementById("count");

document.getElementById("increase")
.addEventListener("click", function() {
count++;
display.textContent = count;
});

document.getElementById("decrease")
.addEventListener("click", function() {
count--;
display.textContent = count;
});`


This example demonstrates how JavaScript updates webpage content based on user interaction.

โšก Quick Revision

โ€ข document โ†’ Represents the webpage.

โ€ข getElementById() โ†’ Selects an element by ID.

โ€ข querySelector() โ†’ Selects the first matching element.

โ€ข querySelectorAll() โ†’ Selects all matching elements.

โ€ข textContent โ†’ Changes or retrieves text.

โ€ข innerHTML โ†’ Changes or retrieves HTML markup.

โ€ข style โ†’ Changes CSS styles.

โ€ข classList โ†’ Manages CSS classes.

โ€ข addEventListener() โ†’ Attaches an event handler.

โ€ข createElement() โ†’ Creates an HTML element.

โ€ข appendChild() โ†’ Adds an element.

โ€ข remove() โ†’ Removes an element.

โ€ข .value โ†’ Gets an input's value.

โ€ข parentElement โ†’ Gets the parent element.

๐Ÿ’ก Key Takeaways

โ€ข DOM connects JavaScript with HTML.

โ€ข JavaScript can dynamically modify webpage content and styling.

โ€ข Events make webpages interactive.

โ€ข DOM manipulation is essential for frontend development.

โ€ข Understanding the DOM is a foundation for learning frameworks like React.

๐Ÿ“Œ Double Tap โค๏ธ For More