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 trialLi Mbo
5,096 Pointswhat is the difference between div[id="name1"] and div #name1 ?
Are they the same?
1 Answer
Kevin Korte
28,149 PointsNo, they are not. div[id="name1"]
would select this html
<div id="name1"></div>
where div #name1
would select this html
<div>
<div id="name1"></div>
<!-- this element with id of name1 would be anything; an anchor, h or p tag, form input, or any other element that supports id -->
</div>
As you can see, two very different HTML.
Li Mbo
5,096 PointsLi Mbo
5,096 PointsExtremely helpful ;D and to the point, thanks a lot Kevin!
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsSure thing, you're welcome. If you want to read about all of the attribute selectors, this is my favorite article that explains them.
https://css-tricks.com/attribute-selectors/
Gennadiy Anikeev
2,559 PointsGennadiy Anikeev
2,559 PointsBut what about div#name1? Is it the same as div[id="name1"]?
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsHey Gennadiy, Yes, they would target the same selector.