DAY 16 — Making Your Website Interactive with Events (JavaScript) We’ve come a long way 🔥 From structure (HTML) ➡️ styling (CSS) ➡️ now bringing your website to life with JavaScript events. Today, we learn how websites respond to user actions like clicks, typing, and more. 💡 What Are Events? An event is something a user does on your webpage. Examples: * Clicking a Button 🖱️ * Typing in an input field ⌨️ * Hovering over an element 👆 JavaScript allows us to listen for these actions and respond. 🧠 Real-Life Example Imagine a light switch 💡 * You press it → Light turns ON * You press again → Light turns OFF That press is an event, and the action is the response 🧪 Example Code ```html <!DOCTYPE html> <html> <head> <title>Day 16</title> </head> <body> <h1 id="text">Hello 👋</h1> <button onclick="changeText()">Click Me</button> <script> function changeText() { document.getElementById("text").innerHTML = "You clicked the button! 🎉"; } </script> </body> </html> ``` 🔍 What’s Happening Here? * `onclick` → waits for a click event * When clicked → runs the `changeText()` function * JavaScript updates the text instantly ⚡ Why This Matters With events, you can build: * Buttons that respond * Forms that validate input * Interactive dashboards * Real-world web apps This is where your website stops being static and becomes alive 🔥 🎯 Mini Challenge Try this: * Change the text color when a button is clicked * Or display a message when the user clicks anywhere on the page 🏁 Progress Check You’re now deep into: * HTML ✅ * CSS ✅ * JavaScript basics ✅ You’re no longer just learning… You’re building real web experiences 💻✨ #30DaysOfCode #WebDevelopment #JavaScript #Frontend #BuildInPublic #LearningJourney
JavaScript Events for Interactive Websites
More Relevant Posts
-
🚀 Ever wondered how to dynamically create elements in JavaScript? Let's dive in! 🤓✨ Creating elements dynamically allows developers to generate content on-the-fly, enhancing user experience and interactivity on websites. It's a powerful technique for adding, updating, or removing elements based on user actions or data changes. ⭐️ Why it matters: Dynamic element creation gives developers the flexibility to build responsive and interactive web applications tailored to user needs, leading to a more engaging and personalized user experience. Plus, it optimizes performance by only adding elements when necessary. Here's a simple breakdown: 1️⃣ Create an element using document.createElement() 2️⃣ Set attributes and content for the element 3️⃣ Insert the element into the DOM using appendChild() ```javascript // Create a new paragraph element const newPara = document.createElement('p'); // Add text content newPara.textContent = 'Dynamic content created!'; // Append the element to an existing container document.getElementById('container').appendChild(newPara); ``` Pro tip: Utilize event listeners to dynamically respond to user interactions and update the content accordingly. 🎯 Common mistake alert: Forgetting to reference the container to append the newly created element can result in elements not displaying as intended. Double-check your target container! 🤔 What's the most creative way you've used dynamic element creation in your projects? Share below! Let's inspire each other. 💡🌟 🌐 View my full portfolio and more dev resources at tharindunipun.lk #JavaScript #WebDevelopment #DynamicElements #CodeNewbie #DeveloperTips #FrontendDevelopment #InteractiveWebsites #WebDevProjects #LearnToCode
To view or add a comment, sign in
-
-
💻 Ever wondered how your HTML actually renders in a browser? As developers, we write HTML, CSS, and JavaScript daily… But what really happens behind the scenes when you open a webpage? Let’s break it down 👇 🔹 1. Browser Reads HTML The browser loads your .html file and starts parsing it line by line. 🔹 2. DOM Creation HTML is converted into a structured tree called the DOM (Document Object Model) — this is what JavaScript interacts with. 🔹 3. CSS Parsing All styles are processed and converted into a CSSOM (CSS Object Model). 🔹 4. Render Tree Formation DOM + CSSOM = Render Tree This defines what will actually appear on the screen. 🔹 5. Layout Calculation The browser calculates size and position of every element. 🔹 6. Painting Pixels are drawn on the screen — your UI becomes visible 🎨 🔹 7. JavaScript Execution The browser’s JavaScript engine (like V8) executes code and can dynamically modify the DOM. 🔄 Any DOM change triggers reflow & repaint — impacting performance. 🧠 Key Insight: HTML is not “executed” — it is parsed and transformed into a structure that the browser understands and renders. ⚡ Why this matters: Helps optimize performance Avoid unnecessary DOM updates Write better frontend code Understanding this flow changed how I think about frontend performance and debugging. What part of the rendering process surprised you the most? #WebDevelopment #JavaScript #Frontend #HTML #CSS #BrowserInternals #SoftwareEngineering
To view or add a comment, sign in
-
Build a smart Table of Contents 📖 (Zero JavaScript needed): Making a Table of Contents used to be a pain. You had to write a lot of JavaScript. You had to track the screen to see where the user was reading. It was a lot of hard work. Not anymore. Now, CSS can track it for you. The Setup First, you just need a normal list of links in your HTML. HTML <ol class="list"> <li><a href="#getting-started">Getting Started</a></li> <li><a href="#core-concepts">Core Concepts</a></li> </ol> The Magic Trick Here is the secret CSS. We use two brand new tools to make it work. CSS /* 1. Tell the list to watch the scroll */ .list { scroll-target-group: auto; } /* 2. Highlight the active link */ .toc-list a:target-current { color: blue; font-weight: bold; background: lightblue; } How this works: scroll-target-group: This turns your list into a smart tracker. It watches the page for you. :target-current: This finds the exact link that matches the part of the page you are reading right now. When you scroll down, the blue highlight moves down the list all by itself! A quick warning: This is a brand new CSS tool. Right now, it only works on Chromium browsers (like Google Chrome and Microsoft Edge). It is not ready for all users yet. But keep an eye on it! Soon, we will never need JavaScript for this again. Anyways, CSS is evolving fast. But while these features are cool, layouts are still where most devs struggle. One design, 25 screen sizes… feels like throw and pray. Flexbox and Grid fix that. I wrote a 112-page visual guide that shows you how to build any layout in an afternoon. Grab it here: [ https://lnkd.in/dZmwzdcc ]
To view or add a comment, sign in
-
-
You can build a Scrollspy with pure CSS. No JavaScript required. A few anchor links, modern CSS selectors, and scroll-driven features are enough to highlight the active section automatically. No scroll listeners. No position calculations. No DOM updates. Each section is linked via id, and the navigation uses anchor links. With :target-current, CSS automatically detects which section is active in the viewport. The active link updates in real time — no syncing logic needed. That alone gives you a fully working Scrollspy. But modern CSS offers more control. 1. Highlight active section with :target-current nav a:target-current { background: #4caf50; color: white; } The browser handles the active state based on scroll position. 2. Group scroll behavior with scroll-target-group nav { scroll-target-group: auto; } This enables proper tracking of scroll targets within the container. 3. Scope styles cleanly with @scope @scope (.scroll-spy-wrapper) { nav a:is(:hover, :focus, :target, :target-current) { background: #4caf50; color: white; } } Keeps everything isolated and maintainable. No JavaScript. No performance overhead. No complex logic. Just declarative CSS. CSS now gives you the ability to build interaction patterns that previously required JavaScript. Scrollspy is just one example. If you’re building: • Documentation layouts • Table of contents • Sticky navigation • Section-based pages This approach is cleaner and more scalable. CSS is no longer just styling. It’s becoming a UI behavior layer. Happy styling 🚀 #CSS #Frontend #WebDevelopment #Programming #FrontendDevelopment #WebPerformance #DevTips #ModernCSS #NoJavaScript #UIEngineering
To view or add a comment, sign in
-
-
🚀 Boost Your Website's Conversion Rate with One Simple JavaScript Concept Imagine you're at a restaurant, and you want to order your favorite dish, but the waiter doesn't understand what you mean. That's basically what happens when your website's JavaScript code isn't working as expected. In simple terms, JavaScript is like a messenger between your website's frontend , what users see, and backend , the server, . It helps make your website interactive and dynamic. One crucial JavaScript concept that can make or break your website's conversion rate is understanding events. Events are like triggers that happen when a user interacts with your website, such as clicking a button or scrolling down. For example, let's say you have a website with a call-to-action , CTA, button that says "Sign Up Now." You want to track how many users click on that button. With JavaScript, you can add an event listener to that button that sends a signal to your analytics tool whenever someone clicks it. Here's a simple example: ```javascript const button = document.querySelector, 'button', ; button.addEventListener, 'click', , , = // Send signal to analytics tool , ; ``` By understanding and using events effectively, you can improve your website's user experience, track user behavior, and ultimately boost conversions. Did this help? Save it for later. Check if your website has this problem by reviewing your analytics tool and see if you're tracking button clicks and other user interactions correctly. #WebDevelopment #LearnToCode #JavaScript #CodingTips #TechEducation #WebDesign #ConversionRate #UserExperience #Analytics #TrackingUserBehavior
To view or add a comment, sign in
-
A parser-blocking script stops everything. The browser is reading your HTML top to bottom. It hits a <script> tag with no defer or async attribute. It stops parsing. Downloads the script. Executes it. Then continues building the page. Nothing appears on screen during that entire process. Parser-blocking scripts block the construction and rendering of the DOM until the script is loaded, parsed, and executed. They also create congestion on the network and significantly delay page rendering, impacting metrics like First Contentful Paint and Largest Contentful Paint. Most Shopify themes have at least one. Many have several. Some have them stacked in the <head> where they do the most damage, blocking the entire page render before a single pixel appears. You can use Theme Check to identify possible performance issues in your theme code, including large CSS and JS bundles, references to remote assets, and parser-blocking JavaScript. Finding them is straightforward. Fixing them requires knowing which scripts are safe to defer and which ones have dependencies that need to load in order. ↓ Swipe through. How to find them, what they cost, and how to fix them. How many parser-blocking scripts does your theme have right now? Drop a comment.
To view or add a comment, sign in
-
Efficiently managing multi-page documents is essential for modern web workflows. This guide shows how to build a multi-page document scanner with structured capture and better output control. Try it now: https://lnkd.in/gtdtCjUn #WebDev #DocumentScanning #JavaScript #DevTools
To view or add a comment, sign in
-
Still using scroll event listeners to detect user activity? CSS might already be able to handle that. No JavaScript needed. Ever wondered if users actually scroll through your Terms of Service before clicking "Agree"? Traditionally, verifying this meant heavy JavaScript, listening to scroll events. It was often complex and bad for performance. But a modern CSS-first technique changes everything. It turns CSS into a silent state manager for your JavaScript. Here’s the idea, broken down: 1. You have a scrollable box (like Terms & Conditions) and a sticky "Sign Up" button inside it. 2. Let the box track its scroll position with only `container-type: scroll-state` 3. Then, a CSS container query defines a rule like: “WHEN this box is scrolled to the very bottom...” 4. "...change a non-visual CSS property on the button." For example, set `appearance: button;` (the button still looks the same). 5. This change acts as an invisible flag. 6. Your JavaScript becomes dead simple. When the button is clicked, it doesn’t care about scroll position… 7. It just reads the computed CSS `appearance` property. 8. If the flag is set → proceed. If not → show a confirmation prompt. This is a brilliant separation of concerns: - CSS declaratively tracks scroll state. - JavaScript reacts to final state only. No listeners, no scroll-time overhead. ⚠️ Note: This technique currently works only in Chrome and Edge (~67% support). So it's not production-ready everywhere yet. It’s a glimpse of what’s coming. What other UI patterns could benefit from this “CSS-as-a-state-machine” approach? Ask me for the demo via DM if needed.
To view or add a comment, sign in
-
🚀 From Static to Dynamic — My JavaScript Journey! In my previous posts, I shared my foundation in HTML & CSS. Today, I’m excited to take it a step further and talk about how I explored the power of JavaScript to build dynamic web applications. 💡 Over time, I learned and implemented: • Creating objects dynamically • DOM manipulation for real-time UI updates • Event handling (keyboard interactions) • Fetch API for asynchronous data handling • Understanding HTTP/HTTPS requests • Changing UI elements dynamically (like colors & content) 🌐 Project Highlight: Wikipedia Search Application I built a dynamic web application that allows users to search and fetch real-time data from an API. ✨ Key Features: • Live search using user input • API integration using Fetch • Dynamic rendering of results (title, link, description) • Loading spinner for better user experience This project helped me understand how frontend and backend concepts connect to create real-world applications. 📌 Through this journey, I realized that JavaScript is not just a language — it's the bridge that makes websites interactive and intelligent. I’m continuously learning and improving, and I’m excited to build more impactful projects ahead! #JavaScript #WebDevelopment #FrontendDevelopment #LearningJourney #Projects #APIs #DynamicWebApps #CodingJourney
To view or add a comment, sign in
-
Hidden dropdowns are not built using <select> tag. They are handled by clicking the dropdown element and selecting options using XPath or CSS locator. Sometimes we use loops, waits, Actions class, or JavaScript executor to interact with them Click to open the dropdown First click the dropdown element and then select the option. driver.findElement(By.id("dropdown")).click(); driver.findElement(By.xpath("//li[text()='Option']")).click(); Sometimes dropdown options load dynamically, so we wait until the element is visible. WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[text()='Option']"))).click(); List<WebElement> options = driver.findElements(By.xpath("//ul[@class='dropdown']//li")); for(WebElement op : options){ if(op.getText().equals("India")){ op.click(); break; } } If the element is hidden or not clickable. JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].click();", element); Useful when dropdown appears on hover. Actions act = new Actions(driver); act.moveToElement(driver.findElement(By.id("menu"))).click().perform();
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development