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

James Pointer
James Pointer
5,257 Points

More Selectors Challenge 3/4.

This has been asked a billion times, but I just cannot figure it out!

"Use an Attribute Selector to select the element with the 'title' attribute. Give it a color property with a value of red."

This is my code as it stands:

a[class~="foo"] {
  color:red;
}

What is wrong with that? Thanks in advance.

9 Answers

Chase Lee
Chase Lee
29,275 Points

Let me give you the answer. It's this:

a[title]{
    color: red;
}
James Barnett
James Barnett
39,199 Points

Chase James -

I get that you were taking tidy on someone after going back and forth for a day.

However consider future forum searchers ...

Not really sure how this helps anyone learn anything. If I didn't already know how attribute selectors work I would be no wiser after seeing this answer.

I'm curious what others think about this.

James Barnett
James Barnett
39,199 Points

Original instructions

Use an Attribute Selector to select the element with the 'title' attribute. Give it a color property with a value of red.


I think the confusion over trying to use a class to select a particular element come from phrase the element instead of any element.

The instructions could be better worded as

Use an Attribute Selector to select any element with a 'title' attribute. Give it a color property with a value of red.


I think that makes it much clearer you need something general

a[title]

In English that roughly translates to:

Selects any a element with a title attribute.


Instead of the very specific:

a[class~="foo"]

In English that roughly translates to:

Selects any a element with a class attribute that contains the word foo.

Explainations from the SelectORacle

Guil Hernandez
Guil Hernandez
Treehouse Teacher

James Barnett – I see how the question is somewhat misleading. The good news is that I'm currently in the process of reshooting the first 3 stages of CSS Foundations. Part of this is rewriting some of the quizzes and code challenges. This will be one of them. :)

Thanks!

Elliott Frazier
Elliott Frazier
Courses Plus Student 9,647 Points

Guil Hernandez - does the reshoot for the first three stages contain more information, or are your reshooting for other reasons?

Guil Hernandez
Guil Hernandez
Treehouse Teacher

Elliott Frazier,

The same content will be covered, though much improved. I just felt like too much information was crammed into each video and the pace was too fast for beginners. So in the new videos, we slowed down the pace and broke the content up into more digestible bits of info. We're also adding awesome new graphics to help explain the content. :)

Elliott Frazier
Elliott Frazier
Courses Plus Student 9,647 Points

Guil Hernandez - Yea I remembered having to re-watch some of the videos to grasp it all. Will I have to earn those badges again after you replace the old ones?

Guil Hernandez
Guil Hernandez
Treehouse Teacher

Elliott Frazier – Nope, you shouldn't have to earn them again. But feel free to watch them :)

Chase Lee
Chase Lee
29,275 Points

To select something with a class you would do this:

a.foo{
   color: red;
}

Hope that helps.

James Pointer
James Pointer
5,257 Points

It still doesn't work, it's supposed to be using the method in the Basic Selectors part 2 tutorial I think?

Chase Lee
Chase Lee
29,275 Points

What attribute does it tell you to select? Put only that into the square brackets.

Elliott Frazier
PLUS
Elliott Frazier
Courses Plus Student 9,647 Points

I think you need to remove the quotation marks from around "foo".

James Pointer
James Pointer
5,257 Points

Nope, neither work, getting rather annoying as I don't want to leave a section out and it really doesn't seem like I'm doing anything wrong, I'm doing it exactly as explained in the video as far as I can tell!..

Patrick Johnson
Patrick Johnson
9,505 Points

Are you sure you're using the proper attribute selector? CSS-Tricks as a good little recap on what they all are. http://css-tricks.com/attribute-selectors/

Can you give more details to your issue? Without proper context it's tough to really help you out.

James Pointer
James Pointer
5,257 Points

I must not be although that is how it is taught in the video tutorial beforehand, or how I understand it at least. This is what the instructions say to do:

"Use an Attribute Selector to select the <a> element with the 'title' attribute. Give it a color property with a value of red."

And the title of the attribute that needs selecting is "foo". So I'm not sure what's wrong. Hope this helps a little more?

Thanks for that link also.

James Pointer
James Pointer
5,257 Points

What do you know, I just figured it out! Thanks for everyones answers :)

Hey the first answer to this code challenge is

div > a{ color:green font-weight:bold }

right? i think my browser isn't working responding right or something please let me know if I am wrong

James Pointer
James Pointer
5,257 Points

I'm not sure if that's the right code or not, but one thing I noticed is that you're missing a couple of semi colons out. :)