๐ HTML = Structure
๐ CSS = Design
๐ JavaScript = Brain (Logic + Interactivity)
๐ง What is JavaScript?
๐ Programming language used to:
โข Add interactivity
โข Handle user actions
โข Update content dynamically
๐ก Example:
โข Button click
โข Form validation
โข Show/hide elements
๐ Variables (Store Data)
let name = "Deepak";
let age = 25;
๐ Used to store values
๐ Conditions (Decision Making)
if (age > 18) {
console.log("Adult");
}
๐ Loops (Repeat Work)
for (let i = 1; i <= 5; i++) {
console.log(i);
}
๐ง Functions (Reusable Code)
function greet() {
console.log("Hello World");
}
greet();
๐ DOM Manipulation (Most Important ๐ฅ)
๐ DOM = Document Object Model
๐ Lets you control HTML using JS
document.getElementById("title").innerText = "Hello JS ๐";
๐ก You can:
โข Change text
โข Change styles
โข Add/remove elements
๐ฑ๏ธ Events (User Actions)
document.getElementById("btn").addEventListener("click", function() {
alert("Button clicked!");
});
๐ Common events:
โข click
โข input
โข submit
๐ฏ Mini Project
๐ Create a button:
โข On click โ change text
โข On click โ change background color
โก Mini Project โ Complete Solution (Button Interaction) ๐ฅ
๐ Button click โ change text + change background color
๐ป Full Code
<!DOCTYPE html>
<html>
<head>
<title>JS Mini Project</title>
<style>
body {
text-align: center;
margin-top: 50px;
}
button {
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
}
</style>
</head>
<body>
<h1 id="title">Hello World ๐</h1>
<button id="btn">Click Me ๐</button>
<script>
document.getElementById("btn").addEventListener("click", function() {
// Change text
document.getElementById("title").innerText = "You clicked the button! ๐";
// Change background color
document.body.style.backgroundColor = "lightblue";
});
</script>
</body>
</html>
๐ง How It Works (Simple Breakdown)
1๏ธโฃ Select Button
document.getElementById("btn")
2๏ธโฃ Add Click Event
.addEventListener("click", function() {})
3๏ธโฃ Change Text
document.getElementById("title").innerText = "New Text"
4๏ธโฃ Change Background
document.body.style.backgroundColor = "lightblue"
๐ฏ Output
๐ Click button โ
โ Text changes
โ Background color changes
๐ฅ Bonus Challenge
๐ Add:
โข Toggle colors (switch back forth)
โข Count number of clicks
โข Show alert message
๐ก Pro Tips
โข Focus heavily on DOM + Events
โข Practice small interactions daily
โข Use browser console to test code
๐ฏ Outcome
After this:
โ You can add interactivity
โ You understand logic building
โ Ready for Advanced JavaScript
Double Tap โค๏ธ For More