Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Using jQuery Plugins Add a Sticky Navigation Bar The Plugin Challenge Solution

Editing CSS directly vs using jQuery

Hi there - when I did this I actually edited the CSS and HTML directly in the jQuery using the .css() and .html() methods. Is it better practice to edit things directly in the CSS and HTML files wherever possible?

2 Answers

Stephan Olsen
Stephan Olsen
6,650 Points

Sorry Michael, I did mean that you should NOT be using JavaScript/jQuery for static styling. I've edited my answer now. With that I mean that you should not use JavaScript/jQuery to define the styling of your website. You should using it for interactivity. For example if a user clicks a button, you could use jQuery to change the styling of some element. But you should not be using jQuery to setting the initial styling of this element.

I did not watch his video, but basically, any styling that you can put in a stylesheet, should be put in the stylesheet.

Makes perfect sense - thanks very much Stephan!

Stephan Olsen
Stephan Olsen
6,650 Points

You should not be creating your stylesheet with jQuery so to say. Your styling should be kept in a seperate stylesheet. This makes it easy to track which elements have which styles, and it makes it easy to change the styling. You can use JavaScript and jQuery to change the styling depending on some action the user performs. But you should not be making static styling with JavaScript/jQuery.

Thanks for such a speedy and helpful response Stephan! Can I just double check - in your last sentence, did you mean to say 'But you should NOT be making static styling with JavaScript/jQuery'? Have I understood that right?

Also, what makes styling 'static'? Is the styling behind the 'We build great apps' and 'email us' bars in this video static?

Thanks again!