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 jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 2

Adam Łakomy
Adam Łakomy
10,718 Points

We adding HTML by jQuery but not CSS. It is not very consist for me because user w/o JS still download CSS for JS only

So Andrew here telling that best practise is to append additional HTML code by jQuery. That is preventing downloading additional data by user without acess to JS. But on the other hand we adding tons of CSS with no worries? It is not very consistent aproach for me. Is it any particular reason for not adding CSS by jQuery also?

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

Browsers, in the main options controls, can be set to not load JavaScript, yet will always load CSS. Preventing CSS from loading can be changed in the browser's developer tools or browser plugins, for example, but this option is not typically available in the standard options. JavaScript can affect potential security issues so that's why the option is there. CSS can only affect the display of the layout.

In regards to your last question, jQuery can be used to include additional CSS, although it is generally not preferred as then there is really no way to change the look and feel without editing the js code. Typically the rule of thumb is to keep layout display separate from the logic as much as possible. For example, if one were creating a jQuery plugin then also create a separate CSS file to accommodate it so that users of the plugin can adjust the styles to their preferences.

Adam Łakomy
Adam Łakomy
10,718 Points

Thank you for complement topic.