JavaScript JavaScript and the DOM Making Changes to the DOM Creating New DOM Elements

Ian Salmon
PRO
Ian Salmon
Pro Student 10,659 Points

Use ID or CLASS when adding a button?

I noticed that:

toggleList button uses id="toggleList"

change list description button uses class="description"

add item button uses class="addItemButton"

Is there any currently relevant reason to choose one over the other when creating buttons? Class or id?

1 Answer

Brendan Whiting
MOD
Brendan Whiting
Front End Web Development Treehouse Moderator 84,071 Points

There can only be one tag with that id, but many with the same class. Use classes if you think you might have other buttons like it in the future. There's a school of thought that you should avoid ids and just use classes.