Index

The DOM

The Document Object Model is the interface where JS meets HTML and CSS.

    
      // Select an element
      var header = document.querySelector("h1");

      // Manipulate the selection
      header.style.color = "rebeccapurple";
    
  

    
      // Select an element
      var body = document.querySelector("body");
      var isPurple = false;

      // Manipulate the selection
      setInterval(function(){
        if(isPurple) {
          body.style.background = "coral";
        } else {
          body.style.background = "rebeccapurple";
        }
        isPurple = !isPurple;
      }, 2000);
    
  

  1. DOM Selection

  2. Everything revolves around the document.

    Direct Selection

    Methods


  3. DOM Manipulation



  4. DOM Events

  5. Making things interactive.

    We first SELECT and element and then add an EVENT LISTENER to it.

    EX. "Listening for a click on a specific button"

          
            element.addEventListener(type, functionToCall);
    
            var btn = document.querySelector("button");
            btn.addEventListener("click", function() {
              console.log("Hey! stop clicking on me!");
            });
          
        

    :( No one has clicked on me...


    Events

    There are hundreds and hundreds of events, you can see them all HERE.