Week 6 Blog Post

Blog Question

Describe how the querySelector() and querySelectorAll() methods work. What is the difference between the values returned for each method? Use an example code snippet to support your answer; include sample HTML and JS selectors.

querySelector() is taking the CSS Style selector and It returns the first element that matches a given CSS Style Selector.

function yeet(){
          document.querySelector("p").style.backgroundColor = "cyan";
}

querySelectorAll() returns all elements of the specified CSS selector

function yeet() {
  let n, i;
  n = document.querySelectorAll(".example");
  for (i = 0; i < x.length; i++) {
    n[i].style.backgroundColor = "cyan";
  }
}

Directory Link

Leave a comment

Your email address will not be published. Required fields are marked *

css.php