Skip to content

The Colorful Chameleon #12

Discussion options

You must be logged in to vote
document.querySelectorAll('p').forEach(p => p.style.color = 'blue');

Details:

  1. document.querySelectorAll('p'): This method selects all

    elements in the document. It returns a NodeList, which is a collection of elements.

2..forEach(p => ... ): The forEach method is used to iterate over each element in the NodeList. It takes a callback function as an argument, which is executed for each element.

3 p => p.style.color = 'blue': This is an arrow function that takes a single parameter p (representing each

element). Inside the function, p.style.color = 'blue' sets the color property of the element's style to 'blue'.

So, this one-liner code effectively selects all

elements and changes their t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by meviru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants