Questions

This post is about the questions I have regarding programming

Β·

1 min read

I've decided to make a post about the questions I get during studying so I can check it out in the future.

JavaScript

πŸ™‹β€β™€οΈ How to make several elements to change the properties using DOM querySelectorAll?

[HTML]
      <h1>test</h1>
       <ul>
            <li class = "item">1</li>
            <li class = "item">2</li>
            <li class = "item">3</li>
        </ul>

[JavaScript]
       document.querySelector("item").style.color = "red";

above will just change the colour of first item which is "1"

βœ… I have found the answer!

image.png

I should have used the for loop to make all red. in the order of [0] -> [1] -> [2]

πŸ™‹β€β™€οΈ How to set onclick on <a>tag?

image.png

I want to change the colour of text which has Tag but it doesn't work😭

βœ… I have found the answer!

image.png

I've changed the selector tag to <a> instead of <p> and it worked! but why? do I need to specify the tag the one which is very close to the content?

Β