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


Changing div formatting. In what instances would you use JavaScript?

JavaScript is used in coordination with HTML and CSS. CSS is used obviously for styling your HTML page. As I'm watching the JavaScript Basics video on variables, it is showing me how to change properties of HTML divs using JavaScript and I am left asking myself why I would use this instead of doing it in CSS. Is this just a basic functionality of JavaScript that I will most likely never end up using, or should I remember this, as it will be utilized in the future?

1 Answer

Hi Colton,

You can use that functionality to dynamically change something on the page. For example, lets say there is an option to click on something that says enlarge image. When that click event occurs you could have Javascript change the class of the div which could then be "targeted" by a different css selector to change the size of the image.