+ 3

What is the difference between an 'id' selectors and 'class' selectors?

Consider these: <section id = "paragraph1"> <p>This is the first paragraph</p> </section> // or <section class= "paragraph1"> <p>This is the first paragraph</p> </section> // I'm confused, DOM is tricky.

22nd Apr 2019, 2:16 AM
Nootnoot
Nootnoot - avatar
1 Resposta
+ 3
Well an id selector is only supposed to be used once for a single element but a class selector can be used mutiple times. Example: <div class="partOne" id="sectionOne"> </div> <div class="partOne" id="sectionTwo"> </div> <div class="partOne" id="sectionThree"> </div> And then in JavaScript they are called in two different ways: For individual elements with assigned IDs: document.getElementById("sectionOne"); and for groups of elements with an assigned class: document.getElementsByClassName("partOne");
22nd Apr 2019, 2:56 AM
Decimis † 𝕯𝖊𝖈𝖎𝖒𝖎𝖘
Decimis † 𝕯𝖊𝖈𝖎𝖒𝖎𝖘 - avatar