Giter Club home page Giter Club logo

int-u3l4-23-24-student-exercises's Introduction

Lesson 3.4: DOM Manipulation, Part 1

Welcome to the reference guide for Lesson 3.4! Here you'll find key points and code snippets to help you recall and further understand the concepts we covered. Use this as a tool to review and reinforce your learning.

Overview

The Document Object Model (DOM) allows us to interact with and modify the structure, style, and content of websites using JavaScript. In this lesson, we learned about two properties: .innerHTML and .src.

.innerHTML Property

  • Definition: The .innerHTML property allows you to get or change the content of an HTML element.

  • Usage:

    element.innerHTML = "New content here!";
  • Example: If you have an HTML paragraph:

    <p id="demo">Hello, World!</p>

    Using JavaScript, you can change its content:

    document.getElementById("demo").innerHTML = "I'm different!";

.src Property

  • Definition: The .src property allows you to get or set the source URL of an <img> element.

  • Usage:

    imageElement.src = "newImageURL.jpg";
  • Example: Given an HTML image element:

    <img id="pic" src="oldImageURL.jpg">

    Using JavaScript, you can change its source URL:

    document.getElementById("pic").src = "newImageURL.jpg";

Manipulating the DOM with Events

To make your changes more dynamic, you can attach events.

  • Example:
    let button = document.querySelector("button");
    let header = document.querySelector("h1");
    
    button.addEventListener("click", function() {
        header.innerHTML = "This is important!";
    });

Event Types

There are many types of events you can listen for, including:

  • "click"
  • "mouseover"
  • "mouseout"
  • "keydown"
  • "keypress"

Usage:

element.addEventListener("eventtype", function() { 
  // actions to be executed 
});

Happy coding!

int-u3l4-23-24-student-exercises's People

Contributors

cn-curriculum avatar cn-mika avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.