Giter Club home page Giter Club logo

dom_manipulation's Introduction

Introduction to DOM Manipulation

Goals:

  • Identifying the DOM

  • Focusing on key terminology/methods used in DOM manipulation

  • Access, add, alter and remove DOM elements

    What is the DOM?

    • DOM stands for Document Object Model
    • When does the DOM get created? When HTML is being loaded from a server, the browser takes the HTML and converts it to the DOM
    • It is a programming interface of your HTML or XML that is created by the browser
    • Offers a web page as a tree of objects
    • We use JavaScript with the DOM to make cool things happen!
    • The DOM is a tree of nodes and each node has its own properties and methods
    • What is a node? Anything we can change in the document: element, Text, HTML attributes
    • These nodes also have relationships to one another
    • Element relationships can be really useful for traversing the DOM. This means accessing elements from other elements

    How to access elements

    Returning 1 element:

    • document.getElementById()
      • accepts id as an argument
      • returns first match
    • document.querySelector()
      • returns the first value that matches the provided selector.
      • This selector accepts tag names, class names and id’s

    Returning multiple element:

    • document.getElementsByClassName()
      • accepts class as an argument
      • returns an HTMLcollection
    • document.getElementsByTagName()
      • accepts tag name as an argument
      • returns an HTMLcollection
    • document.querySelectorAll()
      • returns a node list that matches the provided selector

    Traversing the DOM

    • If moving down the tree, we can use:
      • .children, .querySelector, .querySelectorAll
    • If moving up, we can use
      • .parentElement or .closest
    • We can also traverse sideways
      • nextElementSibling, previousElementSibling

    Adding/Altering Elements on the DOM

    • document.createElement()
    • innerHTML
    • difference between += and =

    Modifying Element text

    • .innerText: Will only return human readable text
    • .textContent: Will return text as well as associated elements like span, style

    Removing elements from the DOM

    • .remove()

    Resources

  • SPA

  • Introduction to the DOM

  • DOM Manipulation

  • innerText vs textContent

  • Using Selectors

dom_manipulation's People

Contributors

aisayo avatar

Watchers

 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.