+ 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.
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");