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

Ian Salmon
Ian Salmon
Pro Student 10,665 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
Brendan Whiting
Front End Web Development Treehouse Moderator 84,579 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.