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

JavaScript

James Blazer
James Blazer
3,836 Points

Adding classes

If there is already css secure class in the style sheet why doesn't it show up until we add it using jquery?

Trent Stenoien
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Trent Stenoien
Full Stack JavaScript Techdegree Graduate 21,632 Points

I'm not sure I understand the question. A code snippet would be helpful.

If I understand correctly you're asking why a style doesn't show on an element until it's added using jQuery?

James Blazer
James Blazer
3,836 Points

Trent, not exactly. I am going through the jQuery section of the fullstack JavaScript course. There was an example where the instructor added a class using jQuery then proceeded to show that the class and styling was already on the style sheet but was not being applied to the html. After she added the jQuery code the style took effect. My question is if the style is already on the style sheet why wasn't it applied to the html before the instructor added it using jQuery?

1 Answer

Trent Stenoien
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Trent Stenoien
Full Stack JavaScript Techdegree Graduate 21,632 Points

Sure. It's because you hadn't told the computer to style that element yet. As an example, let's say you own a house-painting crew. You tell them every time you mark a house with 'X', paint that house red, but every time you mark a house with 'O', they are to paint it blue. If you don't mark a particular house, neither rule will be followed until you do. That is essentially styling a class in CSS does; it helps you tell the browser "if you see X, style it like this...". Does that make sense?

Edit: So before she added the class, she had given no style instructions so it just went to its default. Then when she added the class, she was just telling the browser "to style this element, these are the instructions to follow".