Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Basic Selectors Class Selectors

sorry, but i try to insert also multiple id, and like the class works anyway.

sorry, but i try to insert also multiple id, and like the class works anyway. but the teacher say that can't use the same id more times

1 Answer

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

What do you mean by inserted multiple ids? Do you just mean you have created multiple ids within the HTML document with the same name? And or, applied multiple ids with the same name and different styles?

If the answer is yes to the first one, then that means well of course it will "work" as you won't get any errors in this stage if you are just inserting the same id into an HTML document.

Your true errors will lie in the CSS and any JS code. As the main purpose of using IDs is for Javascript. Can you imagine having two or more elements with the same ID name, and have a JS file targeting that id name but you only wanted to target a specific element? Well that would go terribly wrong.

However, you can test how it won't "work" too with your HTML code. IDs are also commonly used for linking to different sections of your page.

Consider the following HTML code. The anchor element is set up to link to the header element in the document, which will take the user to the header element. Think of it as an internal link.

<header id="top">
  Header Info...
</header>
<a href="#top">Back to top</a>

Now imagine having another element with the same ID name "top". You would be instructing the browser to target the wrong element that you intentionally wanted to.

Hope that helps.