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 trialJustin Goldby
Full Stack JavaScript Techdegree Student 12,754 PointsCan someone explain the benefit of styling a page in Javascript over CSS?
Is Jim just showing us how versatile JS is in this example? Or is he actually implying that it is more beneficial to style my pages in JS?
2 Answers
mikes02
Courses Plus Student 16,968 PointsCSS should be used for styling, not JS. There may be times when styling can be done with JS when appropriate, but for the most part styling should be handled with CSS. For example, jQuery is often used to manipulate CSS values on elements, but those are unique instances, so it generally depends on the circumstances, but as a whole it is best to lean on CSS for styling a website.
Jonathan Grieve
Treehouse Moderator 91,253 PointsThere are also times when you need to put HTML elements onto the page not coded in the original markup. Say for example you want to put a call to action to buy something when a particular element has focus. It'd be easier to just introduce that dynamically. That said, CSS would pick it up whether or not you did it in the JavaScript or not so I prefer to just put it in the stylesheet the usual way. ;)